// ===== 문서 상세 모달 타입 정의 =====

export type DocumentType = 'proposal' | 'expenseReport' | 'expenseEstimate' | 'document' | 'dynamic';

// 결재자 정보
export interface Approver {
  id: string;
  name: string;
  position: string;
  department: string;
  status: 'pending' | 'approved' | 'rejected' | 'skipped' | 'on_hold' | 'none';
  approvedAt?: string;
}

// 품의서 데이터
export interface ProposalDocumentData {
  documentNo: string;
  createdAt: string;
  vendor: string;
  vendorPaymentDate: string;
  title: string;
  description: string;
  reason: string;
  estimatedCost: number;
  attachments?: string[];
  approvers: Approver[];
  drafter: Approver;
}

// 지출결의서 항목
export interface ExpenseReportItem {
  id: string;
  no: number;
  description: string;
  amount: number;
  note: string;
}

// 지출결의서 데이터
export interface ExpenseReportDocumentData {
  documentNo: string;
  createdAt: string;
  requestDate: string;
  paymentDate: string;
  items: ExpenseReportItem[];
  cardInfo: string;
  totalAmount: number;
  attachments?: string[];
  approvers: Approver[];
  drafter: Approver;
}

// 비용견적서 항목
export interface ExpenseEstimateItem {
  id: string;
  expectedPaymentDate: string;
  category: string;
  amount: number;
  vendor: string;
  account: string;
}

// 비용견적서 데이터
export interface ExpenseEstimateDocumentData {
  documentNo: string;
  createdAt: string;
  items: ExpenseEstimateItem[];
  totalExpense: number;
  accountBalance: number;
  finalDifference: number;
  approvers: Approver[];
  drafter: Approver;
}

// 동적 양식 문서 데이터 (API template 기반)
export interface DynamicDocumentData {
  documentNo: string;
  createdAt: string;
  formName: string;
  formCategory?: string;
  fields: Record<string, unknown>;
  fieldLabels?: Record<string, string>;
  approvers: Approver[];
  drafter: Approver;
}

// 연결 문서 데이터 (검사 성적서, 작업일지 등 문서관리에서 생성된 문서)
export interface LinkedDocumentData {
  documentNo: string;
  createdAt: string;
  title: string;
  templateName: string;
  templateCode: string;
  status: string;
  workOrderId?: number;
  documentData: Array<{
    fieldKey: string;
    fieldLabel: string;
    value: unknown;
  }>;
  approvers: Approver[];
  drafter: Approver;
  attachments?: Array<{
    id: number;
    name: string;
    url: string;
  }>;
}

// 문서 상세 모달 모드
export type DocumentDetailMode = 'draft' | 'inbox' | 'reference' | 'completed';

// 문서 상태 (기안함 기준)
export type DocumentStatus = 'draft' | 'pending' | 'approved' | 'rejected' | 'cancelled' | 'on_hold';

// 문서 상세 모달 Props
export interface DocumentDetailModalProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  documentType: DocumentType;
  data: ProposalDocumentData | ExpenseReportDocumentData | ExpenseEstimateDocumentData | LinkedDocumentData | DynamicDocumentData;
  mode?: DocumentDetailMode; // 'draft': 기안함 (상신), 'inbox': 결재함 (승인/반려), 'completed': 완료함
  documentStatus?: DocumentStatus; // 문서 상태
  onEdit?: () => void;
  onCopy?: () => void;
  onApprove?: () => void;
  onReject?: () => void;
  onSubmit?: () => void; // 상신 콜백
  onHold?: () => void; // 보류
  onReleaseHold?: () => void; // 보류해제
  onPreDecide?: () => void; // 전결
  onCancel?: () => void; // 회수
}