<?php

namespace App\Console\Commands;

use App\Jobs\VerifyVehicleProviderMediaJob;
use Carbon\Carbon;
use Illuminate\Console\Command;

class VerifyVehicleProviderMedia extends Command
{
    protected $signature = 'media:verify-vehicle-provider';

    protected $description = 'Dispatch a job to verify recently created vehicle provider media files still exist';

    public function handle(): int
    {
        if (tenant('type') === 'listing') {
            return self::SUCCESS;
        }

        $since = Carbon::now()->hour === 7
            ? Carbon::yesterday()->setTime(20, 0)
            : Carbon::now()->subHour();

        VerifyVehicleProviderMediaJob::dispatch($since);

        return self::SUCCESS;
    }
}
