<?php

namespace App\Support;

class BatchDispatchWarning
{
    /**
     * @return array{warning:string, warning_link_href?:string, warning_link_label?:string, warning_copy_text?:string, warning_copy_label?:string}
     */
    public static function build(
        string $actionLabel,
        string $runId,
        string $batchType,
    ): array {
        $actionLabel = trim((string) $actionLabel);
        $runId = trim((string) $runId);
        $batchType = trim((string) $batchType);

        $msg = '检测到刚刚已提交过同一批次的' . $actionLabel . '任务（1 分钟内）。为避免重复投递，本次未再次提交。';

        if ($runId === '') {
            return AdminFlash::warning($msg);
        }

        $short = RunId::short($runId, $batchType === 'bmpa' ? 7 : 6, 4);
        $msg = '检测到刚刚已提交过同一批次的' . $actionLabel . '任务（1 分钟内，run_id=' . $short . '）。为避免重复投递，本次未再次提交。';

        return AdminFlash::warning(
            $msg,
            '/admin/platform-batches/show?type=' . $batchType . '&run_id=' . urlencode($runId),
            '进入上次批次复盘',
            $runId,
            '复制run_id',
        );
    }
}
