<?php

namespace Kylin\LawCase\Commands;

use Illuminate\Console\Command;
use Kylin\LawCase\Services\DeadlineWarningService;

/**
 * 扫描期限命令
 *
 * 扫描即将到期的案件期限，触发时限预警提醒。
 */
class ScanDeadlinesCommand extends Command
{
    protected $signature = 'law-case:scan-deadlines';

    protected $description = '扫描即将到期的案件期限，触发时限预警';

    public function handle(DeadlineWarningService $service): int
    {
        $this->info('开始扫描时限预警...');

        $triggered = $service->scanUpcomingDeadlines();

        if (empty($triggered)) {
            $this->info('未发现即将到期的日程。');
        } else {
            foreach ($triggered as $item) {
                $this->warn("预警: {$item['title']} - {$item['days_before']}天后到期 ({$item['target_date']})");
            }
            $this->info('共触发 ' . count($triggered) . ' 条预警。');
        }

        return self::SUCCESS;
    }
}
