using SolutionErp.Domain.Contracts;

namespace SolutionErp.Application.Contracts.Dtos;

// 7 typed DTOs cho 7 ContractType-specific Details bảng. Map 1-1 với entity
// trong Domain/Contracts/Details/. Generic ContractDetailItem dùng cho
// list-mixed view (vd Lịch sử changelog reference).

public record ThauPhuDetailDto(Guid Id, int Order, string HangMuc, string DonViTinh, decimal KhoiLuong, decimal DonGia, decimal ThanhTien, DateTime? ThoiGianHoanThanh, string? GhiChu);

public record GiaoKhoanDetailDto(Guid Id, int Order, string MaCongViec, string TenCongViec, string DonViTinh, decimal KhoiLuong, decimal DonGia, decimal ThanhTien, DateTime? ThoiGianHoanThanh, string? YeuCauKyThuat, string? GhiChu);

public record NhaCungCapDetailDto(Guid Id, int Order, string MaSP, string TenSP, string? ThongSoKyThuat, string DonViTinh, decimal SoLuong, decimal DonGia, decimal ThanhTien, DateTime? ThoiGianGiao, string? XuatXu, string? GhiChu);

public record DichVuDetailDto(Guid Id, int Order, string MaDichVu, string TenDichVu, string? MoTa, string DonViTinh, decimal ThoiGian, decimal DonGia, decimal ThanhTien, DateTime? TuNgay, DateTime? DenNgay, string? GhiChu);

public record MuaBanDetailDto(Guid Id, int Order, string MaSP, string TenSP, string? MoTa, string DonViTinh, decimal SoLuong, decimal DonGia, decimal ThueVAT, decimal ThanhTien, string? XuatXu, string? GhiChu);

public record NguyenTacNccDetailDto(Guid Id, int Order, string NhomSP, string TenSP, string DonViTinh, decimal DonGiaToiThieu, decimal DonGiaToiDa, string? DieuKienGiaoHang, string? DieuKienThanhToan, string? GhiChu);

public record NguyenTacDvDetailDto(Guid Id, int Order, string LoaiDichVu, string TenDichVu, string DonViTinh, decimal DonGiaToiThieu, decimal DonGiaToiDa, string? PhamViDichVu, string? SLA, string? GhiChu);

// Wrapper trả về theo Type — FE đọc field tương ứng (chỉ 1 list có data,
// 6 list khác empty). Tránh dùng object/dynamic — TS strict mode.
public record ContractDetailsBundleDto(
    ContractType Type,
    List<ThauPhuDetailDto> ThauPhu,
    List<GiaoKhoanDetailDto> GiaoKhoan,
    List<NhaCungCapDetailDto> NhaCungCap,
    List<DichVuDetailDto> DichVu,
    List<MuaBanDetailDto> MuaBan,
    List<NguyenTacNccDetailDto> NguyenTacNcc,
    List<NguyenTacDvDetailDto> NguyenTacDv);

// Changelog DTO cho FE Lịch sử tab
public record ContractChangelogDto(
    Guid Id,
    ChangelogEntityType EntityType,
    Guid? EntityId,
    ChangelogAction Action,
    ContractPhase? PhaseAtChange,
    Guid? UserId,
    string? UserName,
    string? Summary,
    string? FieldChangesJson,
    string? ContextNote,
    DateTime CreatedAt);
