using SolutionErp.Domain.Budgets;
using SolutionErp.Domain.Contracts;

namespace SolutionErp.Application.Budgets.Dtos;

public record BudgetListItemDto(
    Guid Id,
    string? MaNganSach,
    string TenNganSach,
    int NamNganSach,
    BudgetPhase Phase,
    Guid ProjectId,
    string ProjectName,
    decimal TongNganSach,
    DateTime? SlaDeadline,
    DateTime CreatedAt);

public record BudgetDetailDto(
    Guid Id,
    string GroupCode,
    string GroupName,
    string? ItemCode,
    string NoiDung,
    string? DonViTinh,
    decimal KhoiLuong,
    decimal DonGia,
    decimal ThanhTien,
    int Order,
    string? GhiChu);

public record BudgetApprovalDto(
    Guid Id,
    BudgetPhase FromPhase,
    BudgetPhase ToPhase,
    Guid? ApproverUserId,
    string? ApproverName,
    ApprovalDecision Decision,
    string? Comment,
    DateTime ApprovedAt);

public record BudgetChangelogDto(
    Guid Id,
    BudgetEntityType EntityType,
    Guid? EntityId,
    ChangelogAction Action,
    BudgetPhase? PhaseAtChange,
    Guid? UserId,
    string? UserName,
    string? Summary,
    string? FieldChangesJson,
    string? ContextNote,
    DateTime CreatedAt);

public record BudgetWorkflowSummaryDto(
    string PolicyName,
    string PolicyDescription,
    List<BudgetPhase> ActivePhases,
    List<BudgetPhase> NextPhases);

// Snapshot ngân sách link cho PE / Contract DetailBundle. Compact — chỉ
// header info, không bao gồm BudgetDetails (gọi /budgets/{id} riêng nếu cần
// đối chiếu chi tiết theo từng GroupCode/ItemCode).
public record BudgetSummaryDto(
    Guid Id,
    string? MaNganSach,
    string TenNganSach,
    int NamNganSach,
    BudgetPhase Phase,
    decimal TongNganSach);

public record BudgetDetailBundleDto(
    Guid Id,
    string? MaNganSach,
    string TenNganSach,
    string? Description,
    int NamNganSach,
    BudgetPhase Phase,
    Guid ProjectId,
    string ProjectName,
    Guid? DepartmentId,
    string? DepartmentName,
    Guid? DrafterUserId,
    string? DrafterName,
    decimal TongNganSach,
    DateTime? SlaDeadline,
    DateTime CreatedAt,
    DateTime? UpdatedAt,
    List<BudgetDetailDto> Details,
    List<BudgetApprovalDto> Approvals,
    BudgetWorkflowSummaryDto Workflow);
