/**
 * 근태관리 (AttendanceManagement) 타입 정의
 */

// 근태 상태 타입
export type AttendanceStatus = 'onTime' | 'late' | 'absent' | 'vacation' | 'businessTrip' | 'fieldWork' | 'overtime';

// 근태 상태 라벨
export const ATTENDANCE_STATUS_LABELS: Record<AttendanceStatus, string> = {
  onTime: '정시 출근',
  late: '지각',
  absent: '결근',
  vacation: '휴가',
  businessTrip: '출장',
  fieldWork: '외근',
  overtime: '연장근무',
};

// 근태 상태 색상
export const ATTENDANCE_STATUS_COLORS: Record<AttendanceStatus, string> = {
  onTime: 'bg-green-100 text-green-700',
  late: 'bg-yellow-100 text-yellow-700',
  absent: 'bg-red-100 text-red-700',
  vacation: 'bg-blue-100 text-blue-700',
  businessTrip: 'bg-purple-100 text-purple-700',
  fieldWork: 'bg-orange-100 text-orange-700',
  overtime: 'bg-indigo-100 text-indigo-700',
};

// 필터 옵션
export type FilterOption = 'all' | AttendanceStatus;

export const FILTER_OPTIONS: { value: FilterOption; label: string }[] = [
  { value: 'all', label: '전체' },
  { value: 'onTime', label: '정시 출근' },
  { value: 'late', label: '지각' },
  { value: 'absent', label: '결근' },
  { value: 'vacation', label: '휴가' },
  { value: 'businessTrip', label: '출장' },
  { value: 'fieldWork', label: '외근' },
  { value: 'overtime', label: '연장근무' },
];

// 정렬 옵션
export type SortOption = 'rank' | 'deptAsc' | 'deptDesc' | 'nameAsc' | 'nameDesc';

export const SORT_OPTIONS: { value: SortOption; label: string }[] = [
  { value: 'rank', label: '직급순' },
  { value: 'deptAsc', label: '부서 오름차순' },
  { value: 'deptDesc', label: '부서 내림차순' },
  { value: 'nameAsc', label: '이름 오름차순' },
  { value: 'nameDesc', label: '이름 내림차순' },
];

// 사유 유형 (문서 유형)
export type ReasonType = 'businessTripRequest' | 'vacationRequest' | 'fieldWorkRequest' | 'overtimeRequest';

export const REASON_TYPE_LABELS: Record<ReasonType, string> = {
  businessTripRequest: '출장신청서',
  vacationRequest: '휴가신청서',
  fieldWorkRequest: '외근신청서',
  overtimeRequest: '연장근무신청서',
};

// 근태 기록 인터페이스
export interface AttendanceRecord {
  id: string;
  employeeId: string;
  employeeName: string;
  department: string;
  position: string;
  rank: string;
  baseDate: string;
  checkIn: string | null;
  checkOut: string | null;
  breakTime: string | null;
  overtimeHours: string | null;
  reason: {
    type: ReasonType;
    label: string;
    documentId?: string;
  } | null;
  status: AttendanceStatus;
  createdAt: string;
  updatedAt: string;
}

// 근태 등록/수정 폼 데이터
export interface AttendanceFormData {
  employeeId: string;
  baseDate: string;
  checkInHour: string;
  checkInMinute: string;
  checkOutHour: string;
  checkOutMinute: string;
  nightOvertimeHours: string;
  nightOvertimeMinutes: string;
  weekendOvertimeHours: string;
  weekendOvertimeMinutes: string;
}

// 사유 등록 폼 데이터
export interface ReasonFormData {
  employeeId: string;
  baseDate: string;
  reasonType: ReasonType | '';
}

// 근태 정보 다이얼로그 Props
export interface AttendanceInfoDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  mode: 'create' | 'edit';
  attendance?: AttendanceRecord | null;
  employees: { id: string; name: string; department: string; position: string; rank: string }[];
  onSave: (data: AttendanceFormData) => void;
}

// 사유 정보 다이얼로그 Props
export interface ReasonInfoDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  employees: { id: string; name: string; department: string; position: string; rank: string }[];
  onSubmit: (data: ReasonFormData) => void;
}

// 시간 옵션 생성 헬퍼
export const HOUR_OPTIONS = Array.from({ length: 24 }, (_, i) => ({
  value: String(i),
  label: `${i}시`,
}));

export const MINUTE_OPTIONS = [
  { value: '0', label: '0분' },
  { value: '30', label: '30분' },
];

// 연장 시간 옵션 (0-12시간)
export const OVERTIME_HOUR_OPTIONS = Array.from({ length: 13 }, (_, i) => ({
  value: String(i),
  label: `${i}시간`,
}));