<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Enums\PropertyRequestStatus;
use App\Models\PropertyRequest;
use Illuminate\Console\Command;

class CleanupExpiredRequestsCommand extends Command
{
    protected $signature = 'app:cleanup-expired-requests';

    protected $description = 'Passe au statut « expired » les demandes actives dont la date expires_at est dépassée.';

    public function handle(): int
    {
        $updated = PropertyRequest::query()
            ->where('status', PropertyRequestStatus::Active->value)
            ->whereNotNull('expires_at')
            ->where('expires_at', '<', now())
            ->update(['status' => PropertyRequestStatus::Expired->value]);

        $this->info("Demandes expirées mises à jour : {$updated}.");

        return self::SUCCESS;
    }
}
