<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\Ticket\TicketPendingConfirmReconcileService;

final class TicketPendingConfirmReconcileCommand extends Command
{
    protected $signature = 'lottery:ticket-pending-confirm-reconcile {--stale-minutes=5 : pending_confirm 超过多久进入补偿} {--limit=500 : 每次最多扫描多少笔注单}';

    protected $description = '扫描超时待确认注单，按钱包扣款事实确认或退本释放风控占用';

    public function handle(TicketPendingConfirmReconcileService $service): int
    {
        $staleMinutes = max(1, (int) $this->option('stale-minutes'));
        $limit = max(1, (int) $this->option('limit'));

        $summary = $service->reconcile($staleMinutes, $limit);

        $this->info(sprintf(
            'Ticket pending confirm reconcile scanned: %d, confirmed: %d, refunded: %d',
            $summary['scanned'],
            $summary['confirmed'],
            $summary['refunded'],
        ));

        return self::SUCCESS;
    }
}
