<?php
namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Ticket;

class UpdateSlaStatus extends Command
{
    protected $signature   = 'sla:update';
    protected $description = 'Update SLA status for all open tickets';

    public function handle(): void
    {
        $tickets = Ticket::whereNotIn('status', ['resolved','closed'])
            ->whereNotNull('sla_solve_deadline')
            ->get();

        foreach ($tickets as $ticket) {
            $ticket->updateSlaStatus();
        }
        $this->info("Updated SLA for {$tickets->count()} tickets.");
    }
}
