using SolutionErp.Domain.Contracts;
using SolutionErp.Domain.PurchaseEvaluations;

namespace SolutionErp.Application.PurchaseEvaluations.Services;

public interface IPurchaseEvaluationWorkflowService
{
    // Kiểm tra + thực hiện transition. Throw ForbiddenException nếu không hợp lệ.
    // Tự tạo PurchaseEvaluationApproval + update Phase + SlaDeadline.
    Task TransitionAsync(
        PurchaseEvaluation evaluation,
        PurchaseEvaluationPhase targetPhase,
        Guid? actorUserId,
        IReadOnlyList<string> actorRoles,
        ApprovalDecision decision,
        string? comment,
        CancellationToken ct = default);

    TimeSpan? GetPhaseSla(PurchaseEvaluationPhase phase);
}

// Atomic sequence generator cho mã PE (MaPhieu) — mirror IContractCodeGenerator.
// Format: PE/{YYYY}/{TypeLetter}/{Seq:D3}
//   - YYYY = năm hiện tại (UTC)
//   - TypeLetter = "A" (DuyetNcc) / "B" (DuyetNccPhuongAn)
//   - Seq = 3 chữ số tăng dần per (year × type)
// VD: PE/2026/A/001, PE/2026/A/002, PE/2026/B/001
public interface IPurchaseEvaluationCodeGenerator
{
    // Gen mã phiếu atomic. Transaction SERIALIZABLE để tránh race condition.
    Task<string> GenerateAsync(PurchaseEvaluation evaluation, CancellationToken ct = default);
}
