<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\RevocationSchedule;
use App\Services\ReminderService;
use Carbon\Carbon;

class CheckExtendedReminders extends Command
{
    protected $signature = 'reminder:check-extended';
    protected $description = 'Check reminders for extended access';

    protected $reminderService;

    public function __construct(ReminderService $reminderService)
    {
        parent::__construct();
        $this->reminderService = $reminderService;
    }

    public function handle(): int
    {
        $this->info('🔍 Checking extended access reminders...');

        $schedules = RevocationSchedule::needsExtendedReminder()->get();
        $sentCount = 0;

        foreach ($schedules as $schedule) {
            $this->reminderService->sendReminder($schedule, 'extended_reminder');
            $schedule->markReminderSent('extended');
            $sentCount++;
            $this->info("   📧 Sent extended reminder for: {$schedule->employeeAccessDetail->employee->name}");
        }

        $this->info("✅ Total extended reminders sent: {$sentCount}");
        return 0;
    }
}