<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Business\Product\ProductSkuCompatibilityService;
use Illuminate\Console\Command;

final class DberpProductSkuCompatibilityCommand extends Command
{
    protected $signature = 'dberp:product-sku-compatibility {--dry-run : 仅输出结果，不写库}';

    protected $description = '检查并修复物料默认规格组合、回填历史上为空的规格组合关联（不写数量与金额）';

    public function handle(ProductSkuCompatibilityService $service): int
    {
        $dryRun = (bool) $this->option('dry-run');
        $report = $service->runCompatibilityPass($dryRun);

        $this->info(json_encode($report, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

        return self::SUCCESS;
    }
}
