// 배치 관리 관련 타입 정의
// 작성일: 2024-12-23

export interface BatchJob {
  id?: number;
  job_name: string;
  description?: string | null;
  job_type: string;
  schedule_cron?: string | null;
  is_active: string; // 'Y' | 'N'
  config_json?: Record<string, any> | null;
  last_executed_at?: Date | null;
  next_execution_at?: Date | null;
  execution_count: number;
  success_count: number;
  failure_count: number;
  created_date?: Date | null;
  created_by?: string | null;
  updated_date?: Date | null;
  updated_by?: string | null;
  company_code: string;
}

export interface BatchJobFilter {
  job_name?: string;
  job_type?: string;
  is_active?: string;
  company_code?: string;
  search?: string;
}

export interface BatchExecution {
  id?: number;
  job_id: number;
  execution_status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
  started_at?: Date;
  completed_at?: Date;
  execution_time_ms?: number;
  result_data?: Record<string, any>;
  error_message?: string;
  log_details?: string;
  created_date?: Date;
}

export interface BatchSchedule {
  id?: number;
  job_id: number;
  schedule_name: string;
  cron_expression: string;
  timezone?: string;
  is_active: string;
  last_triggered_at?: Date;
  next_trigger_at?: Date;
  created_date?: Date;
  created_by?: string;
}

export interface BatchMonitoring {
  total_jobs: number;
  active_jobs: number;
  running_jobs: number;
  failed_jobs_today: number;
  successful_jobs_today: number;
  recent_executions: BatchExecution[];
}

// 배치 작업 타입 옵션
export const BATCH_JOB_TYPE_OPTIONS = [
  { value: 'collection', label: '데이터 수집' },
  { value: 'sync', label: '데이터 동기화' },
  { value: 'cleanup', label: '데이터 정리' },
  { value: 'custom', label: '사용자 정의' },
];

// 실행 상태 옵션
export const EXECUTION_STATUS_OPTIONS = [
  { value: 'pending', label: '대기 중' },
  { value: 'running', label: '실행 중' },
  { value: 'completed', label: '완료' },
  { value: 'failed', label: '실패' },
  { value: 'cancelled', label: '취소됨' },
];

// 스케줄 프리셋
export const SCHEDULE_PRESETS = [
  { value: '0 */1 * * *', label: '매시간' },
  { value: '0 0 */6 * *', label: '6시간마다' },
  { value: '0 0 * * *', label: '매일 자정' },
  { value: '0 0 * * 0', label: '매주 일요일' },
  { value: '0 0 1 * *', label: '매월 1일' },
];

export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
}
