<?php

declare(strict_types=1);

namespace App\Command;

use App\Service\OrderAggregatesRefreshJob;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;

/**
 * 手动触发聚合刷新队列消费
 *
 * 与 Crontab 共用 OrderAggregatesRefreshJob，便于运维即时补刷或调试。
 */
#[Command]
class OrderAggregatesRefreshCommand extends HyperfCommand
{
    public function __construct(private OrderAggregatesRefreshJob $job)
    {
        parent::__construct('orders:refresh-aggregates');
    }

    public function configure(): void
    {
        parent::configure();
        $this->setDescription('消费 aggregate_refresh_queue，对滞后日期调用 refresh_continuous_aggregate');
    }

    public function handle(): void
    {
        $result = $this->job->run();
        $this->info(sprintf('Processed: %d, Failed: %d', $result['processed'], $result['failed']));
    }
}
