<?php

namespace App\Console\Commands;

use App\Facades\Settings;
use App\Modules\VehiclesInVideo\Services\TokenService;
use Illuminate\Console\Command;

class VehiclesInVideoCheckTokenExpiryCommand extends Command
{
    protected $signature = 'vehicles-in-video:check-token-expiry';

    protected $description = 'Notify recipients when the Vehicles In Video refresh token is within 30 days of expiry';

    public function handle(TokenService $tokenService): int
    {
        if (Settings::get('vehicles-in-video-enabled') !== true) {
            $this->info('Vehicles In Video integration is disabled. Skipping.');
            return self::SUCCESS;
        }

        $result = $tokenService->checkTokenExpiry();

        match ($result['status']) {
            'error' => $this->error($result['message']),
            'warn' => $this->warn($result['message']),
            default => $this->info($result['message']),
        };

        return $result['status'] === 'error' ? self::FAILURE : self::SUCCESS;
    }
}
