// Phase 10.3 G-O3 (S37 2026-05-28) — Đề xuất (Proposal) types mirror BE
// ProposalFeatures.cs DTO. File MIRROR SHA256 identical với fe-user counterpart.

export const ProposalStatus = {
  Nhap: 1,
  DaGuiDuyet: 2,
  TraLai: 3,
  TuChoi: 4,
  DaDuyet: 5,
} as const
export type ProposalStatusValue = (typeof ProposalStatus)[keyof typeof ProposalStatus]

export const PROPOSAL_STATUS_LABELS: Record<ProposalStatusValue, string> = {
  1: 'Nháp',
  2: 'Đã gửi duyệt',
  3: 'Trả lại',
  4: 'Từ chối',
  5: 'Đã duyệt',
}

export const PROPOSAL_STATUS_BADGE: Record<ProposalStatusValue, string> = {
  1: 'bg-slate-100 text-slate-700 border-slate-300',
  2: 'bg-amber-100 text-amber-800 border-amber-300',
  3: 'bg-orange-100 text-orange-800 border-orange-300',
  4: 'bg-red-100 text-red-800 border-red-300',
  5: 'bg-emerald-100 text-emerald-800 border-emerald-300',
}

export interface ProposalListItemDto {
  id: string
  maDeXuat: string | null
  title: string
  amountEstimate: number | null
  status: ProposalStatusValue
  departmentId: string | null
  departmentName: string | null
  drafterUserId: string
  drafterFullName: string | null
  approvalWorkflowId: string | null
  workflowCode: string | null
  currentApprovalLevelOrder: number | null
  createdAt: string
}

export interface ProposalAttachmentDto {
  id: string
  fileName: string
  filePath: string
  fileSize: number
  mimeType: string | null
  uploadedByUserId: string
  uploadedByFullName: string
  createdAt: string
}

export interface ProposalLevelOpinionDto {
  id: string
  approvalWorkflowLevelId: string
  stepOrder: number | null
  stepName: string | null
  levelOrder: number | null
  approverUserId: string | null
  comment: string | null
  signedAt: string
  signedByUserId: string
  signedByFullName: string
}

export interface ProposalDetailDto extends ProposalListItemDto {
  description: string | null
  workflowName: string | null
  rejectedFromStatus: number | null
  attachments: ProposalAttachmentDto[]
  levelOpinions: ProposalLevelOpinionDto[]
}

export interface CreateProposalInput {
  title: string
  description?: string | null
  amountEstimate?: number | null
  departmentId?: string | null
  approvalWorkflowId?: string | null
}

export interface UpdateProposalDraftInput extends CreateProposalInput {}

export interface PagedResult<T> {
  items: T[]
  total: number
  page: number
  pageSize: number
  totalPages: number
  hasNext: boolean
  hasPrev: boolean
}
