// ===== 문서 작성 타입 정의 =====

// 업로드된 파일 정보
export interface UploadedFile {
  id: number;
  name: string;
  url: string;
  size?: number;
  mime_type?: string;
}

// 문서 유형 (기존 3종 + API 기반 확장)
export type DocumentType = 'proposal' | 'expenseReport' | 'expenseEstimate' | string;

// 전용 폼이 있는 코드 (API code + frontend camelCase 모두 포함)
export const DEDICATED_FORM_CODES = [
  // 기존 3종
  'proposal', 'expenseReport', 'expense_report', 'expenseEstimate', 'expense_estimate',
  // 일반
  'official_letter', 'officialDocument',
  // 인사/근태
  'resignation',
  'leave_promotion_1st', 'leaveNotice1st',
  'leave_promotion_2nd', 'leaveNotice2nd',
  'delegation', 'powerOfAttorney',
  'board_minutes', 'boardMinutes',
  // 증명서
  'employment_cert', 'employmentCert',
  'career_cert', 'careerCert',
  'appointment_cert', 'appointmentCert',
  'seal_usage', 'sealUsage',
  // 재무
  'quotation',
] as const;

export const DOCUMENT_TYPE_OPTIONS: { value: DocumentType; label: string }[] = [
  { value: 'proposal', label: '품의서' },
  { value: 'expenseReport', label: '지출결의서' },
  { value: 'expenseEstimate', label: '비용견적서' },
];

// 결재 단계 유형
export type StepType = 'approval' | 'agreement';

// 결재자/참조자 정보
export interface ApprovalPerson {
  id: string;
  department: string;
  position: string;
  name: string;
  stepType?: StepType; // 결재(approval) 또는 합의(agreement)
}

// 기본 정보
export interface BasicInfo {
  drafter: string;
  drafterPosition?: string;
  drafterDepartment?: string;
  draftDate: string;
  documentNo: string;
  documentType: DocumentType;
  formId?: number;          // API 양식 ID
  formCode?: string;        // API 양식 코드
  formName?: string;        // API 양식 이름
  formCategory?: string;    // API 양식 카테고리
  isUrgent?: boolean;       // 긴급 여부
}

// 품의서 데이터
export interface ProposalData {
  vendorId: string;              // 거래처 ID (API 연동)
  vendor: string;                // 거래처명 (표시용)
  vendorPaymentDate: string;
  title: string;
  description: string;
  reason: string;
  estimatedCost: number;
  attachments: File[];           // 새로 추가할 파일
  uploadedFiles?: UploadedFile[]; // 이미 업로드된 파일
}

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

// 지출결의서 데이터
export interface ExpenseReportData {
  requestDate: string;
  paymentDate: string;
  items: ExpenseReportItem[];
  cardId: string;
  totalAmount: number;
  attachments: File[];           // 새로 추가할 파일
  uploadedFiles?: UploadedFile[]; // 이미 업로드된 파일
}

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

// 비용견적서 데이터
export interface ExpenseEstimateData {
  title: string;
  body: string;
  items: ExpenseEstimateItem[];
  totalExpense: number;
  accountBalance: number;
  finalDifference: number;
}

// ===== 신규 12종 전용 폼 데이터 =====

// 공문서
export interface OfficialDocumentData {
  documentNumber: string;
  documentDate: string;
  recipient: string;
  reference: string;
  title: string;
  body: string;
  attachment: string;
  companyName: string;
  representativeName: string;
  address: string;
  phone: string;
  fax: string;
  email: string;
}

// 사직서
export interface ResignationData {
  employeeId: string;
  department: string;
  position: string;
  employeeName: string;
  residentNumber: string;
  joinDate: string;
  resignDate: string;
  employeeAddress: string;
  reasonType: string;
  reasonDetail: string;
  submitDate: string;
}

// 재직증명서
export interface EmploymentCertData {
  employeeId: string;
  employeeName: string;
  residentNumber: string;
  employeeAddress: string;
  companyName: string;
  businessNumber: string;
  department: string;
  position: string;
  employmentPeriodStart: string;
  employmentPeriodEnd: string;
  purpose: string;
  issueDate: string;
}

// 경력증명서
export interface CareerCertData {
  employeeId: string;
  employeeName: string;
  residentNumber: string;
  birthDate: string;
  employeeAddress: string;
  companyName: string;
  businessNumber: string;
  representativeName: string;
  companyPhone: string;
  companyAddress: string;
  department: string;
  positionTitle: string;
  workPeriodStart: string;
  workPeriodEnd: string;
  duties: string;
  purpose: string;
  issueDate: string;
}

// 위촉증명서
export interface AppointmentCertData {
  employeeId: string;
  employeeName: string;
  residentNumber: string;
  department: string;
  phone: string;
  appointmentPeriodStart: string;
  appointmentPeriodEnd: string;
  contractQualification: string;
  purpose: string;
  issueDate: string;
}

// 사용인감계
export interface SealUsageData {
  sealImprint: string;
  purpose: string;
  submitTo: string;
  attachedDocuments: string;
  usageDate: string;
  companyName: string;
  businessNumber: string;
  address: string;
  representativeName: string;
}

// 연차촉진 1차
export interface LeaveNotice1stData {
  employeeId: string;
  department: string;
  position: string;
  totalDays: number;
  usedDays: number;
  remainingDays: number;
  deadline: string;
  legalNotice: string;
}

// 연차촉진 2차
export interface LeaveNotice2ndData {
  employeeId: string;
  department: string;
  position: string;
  remainingDays: number;
  designatedDates: string[];
  legalNotice: string;
}

// 위임장
export interface PowerOfAttorneyData {
  principalCompanyName: string;
  principalBusinessNumber: string;
  principalAddress: string;
  principalRepresentative: string;
  agentName: string;
  agentBirthDate: string;
  agentAddress: string;
  agentPhone: string;
  agentDepartment: string;
  delegationDetails: string;
  delegationPeriodStart: string;
  delegationPeriodEnd: string;
  attachedDocuments: string;
}

// 이사회의사록
export interface BoardMinutesData {
  meetingDate: string;
  meetingPlace: string;
  totalDirectors: number;
  attendingDirectors: number;
  totalAuditors: number;
  attendingAuditors: number;
  agendaTitle: string;
  agendaResult: string;
  chairperson: string;
  proceedings: string;
  adjournmentTime: string;
  signatories: string;
}

// 견적서 항목
export interface QuotationItem {
  id: string;
  name: string;
  specification: string;
  quantity: number;
  unitPrice: number;
  supplyAmount: number;
  tax: number;
  note: string;
}

// 견적서
export interface QuotationData {
  recipientName: string;
  quotationDate: string;
  businessNumber: string;
  companyName: string;
  representativeName: string;
  companyAddress: string;
  businessType: string;
  businessCategory: string;
  companyPhone: string;
  accountNumber: string;
  autoTax: boolean;
  items: QuotationItem[];
  specialNotes: string;
}

// 전체 문서 데이터
export interface DocumentFormData {
  basicInfo: BasicInfo;
  approvalLine: ApprovalPerson[];
  references: ApprovalPerson[];
  proposalData?: ProposalData;
  expenseReportData?: ExpenseReportData;
  expenseEstimateData?: ExpenseEstimateData;
  officialDocumentData?: OfficialDocumentData;
  resignationData?: ResignationData;
  employmentCertData?: EmploymentCertData;
  careerCertData?: CareerCertData;
  appointmentCertData?: AppointmentCertData;
  sealUsageData?: SealUsageData;
  leaveNotice1stData?: LeaveNotice1stData;
  leaveNotice2ndData?: LeaveNotice2ndData;
  powerOfAttorneyData?: PowerOfAttorneyData;
  boardMinutesData?: BoardMinutesData;
  quotationData?: QuotationData;
  dynamicFormData?: Record<string, unknown>; // 동적 폼 데이터 (API template 기반)
}

// 카드 옵션
export const CARD_OPTIONS = [
  { value: 'ibk-1234', label: 'IBK기업카드_1234 (카드명)' },
  { value: 'shinhan-5678', label: '신한카드_5678 (카드명)' },
  { value: 'kb-9012', label: 'KB국민카드_9012 (카드명)' },
];

