<?php

namespace App\Console\Commands;

use App\Services\AgentSettlement\AgentSettlementPeriodCloseService;
use Illuminate\Console\Command;

final class SettlementAgentPeriodCloseCommand extends Command
{
    protected $signature = 'settlement:agent-period-close {period : Settlement period ID}';

    protected $description = '关闭代理账期并生成账单（试运行聚合）';

    public function handle(AgentSettlementPeriodCloseService $service): int
    {
        $periodId = (int) $this->argument('period');
        $result = $service->closePeriod($periodId);
        $this->info(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

        return self::SUCCESS;
    }
}
