// Types cho 7 ContractType-specific Details + Changelog. 1-1 với BE DTOs ở
// Application/Contracts/Dtos/ContractDetailDtos.cs.

export type ThauPhuDetail = {
  id: string
  order: number
  hangMuc: string
  donViTinh: string
  khoiLuong: number
  donGia: number
  thanhTien: number
  thoiGianHoanThanh: string | null
  ghiChu: string | null
}

export type GiaoKhoanDetail = {
  id: string
  order: number
  maCongViec: string
  tenCongViec: string
  donViTinh: string
  khoiLuong: number
  donGia: number
  thanhTien: number
  thoiGianHoanThanh: string | null
  yeuCauKyThuat: string | null
  ghiChu: string | null
}

export type NhaCungCapDetail = {
  id: string
  order: number
  maSP: string
  tenSP: string
  thongSoKyThuat: string | null
  donViTinh: string
  soLuong: number
  donGia: number
  thanhTien: number
  thoiGianGiao: string | null
  xuatXu: string | null
  ghiChu: string | null
}

export type DichVuDetail = {
  id: string
  order: number
  maDichVu: string
  tenDichVu: string
  moTa: string | null
  donViTinh: string
  thoiGian: number
  donGia: number
  thanhTien: number
  tuNgay: string | null
  denNgay: string | null
  ghiChu: string | null
}

export type MuaBanDetail = {
  id: string
  order: number
  maSP: string
  tenSP: string
  moTa: string | null
  donViTinh: string
  soLuong: number
  donGia: number
  thueVAT: number
  thanhTien: number
  xuatXu: string | null
  ghiChu: string | null
}

export type NguyenTacNccDetail = {
  id: string
  order: number
  nhomSP: string
  tenSP: string
  donViTinh: string
  donGiaToiThieu: number
  donGiaToiDa: number
  dieuKienGiaoHang: string | null
  dieuKienThanhToan: string | null
  ghiChu: string | null
}

export type NguyenTacDvDetail = {
  id: string
  order: number
  loaiDichVu: string
  tenDichVu: string
  donViTinh: string
  donGiaToiThieu: number
  donGiaToiDa: number
  phamViDichVu: string | null
  sla: string | null
  ghiChu: string | null
}

export type ContractDetailsBundle = {
  type: number                                          // ContractType int
  thauPhu: ThauPhuDetail[]
  giaoKhoan: GiaoKhoanDetail[]
  nhaCungCap: NhaCungCapDetail[]
  dichVu: DichVuDetail[]
  muaBan: MuaBanDetail[]
  nguyenTacNcc: NguyenTacNccDetail[]
  nguyenTacDv: NguyenTacDvDetail[]
}

// ===== Changelog =====

export const ChangelogEntityType = {
  Contract: 1,
  Detail: 2,
  Workflow: 3,
  Comment: 4,
  Attachment: 5,
} as const
export type ChangelogEntityType = typeof ChangelogEntityType[keyof typeof ChangelogEntityType]

export const ChangelogEntityTypeLabel: Record<number, string> = {
  1: 'HĐ',
  2: 'Chi tiết',
  3: 'Quy trình',
  4: 'Góp ý',
  5: 'File đính kèm',
}

export const ChangelogAction = {
  Insert: 1,
  Update: 2,
  Delete: 3,
  Transition: 4,
} as const
export type ChangelogAction = typeof ChangelogAction[keyof typeof ChangelogAction]

export const ChangelogActionLabel: Record<number, string> = {
  1: 'Tạo',
  2: 'Cập nhật',
  3: 'Xóa',
  4: 'Chuyển phase',
}

export type ContractChangelog = {
  id: string
  entityType: number
  entityId: string | null
  action: number
  phaseAtChange: number | null
  userId: string | null
  userName: string | null
  summary: string | null
  fieldChangesJson: string | null
  contextNote: string | null
  createdAt: string
}
