import { z } from 'zod';

// ===== 카드 상태 =====
export type CardStatus = 'active' | 'suspended';

export const CARD_STATUS_LABELS: Record<CardStatus, string> = {
  active: '사용',
  suspended: '중지',
};

export const CARD_STATUS_COLORS: Record<CardStatus, string> = {
  active: 'bg-green-100 text-green-800',
  suspended: 'bg-red-100 text-red-800',
};

export const CARD_STATUS_OPTIONS = [
  { value: 'all', label: '전체' },
  { value: 'active', label: '사용' },
  { value: 'suspended', label: '중지' },
] as const;

// ===== 카드사 목록 =====
export const CARD_COMPANIES = [
  { value: 'shinhan', label: '신한카드' },
  { value: 'kb', label: 'KB국민카드' },
  { value: 'samsung', label: '삼성카드' },
  { value: 'hyundai', label: '현대카드' },
  { value: 'lotte', label: '롯데카드' },
  { value: 'bc', label: 'BC카드' },
  { value: 'woori', label: '우리카드' },
  { value: 'hana', label: '하나카드' },
  { value: 'nh', label: 'NH농협카드' },
  { value: 'ibk', label: 'IBK기업은행' },
] as const;

export type CardCompany = typeof CARD_COMPANIES[number]['value'];

export const getCardCompanyLabel = (value: CardCompany | string): string => {
  const company = CARD_COMPANIES.find(c => c.value === value);
  return company?.label || value;
};

// ===== 카드 종류 (법인/개인 등) =====
export const CARD_TYPE_OPTIONS = [
  { value: 'corporate_1', label: '법인 1종' },
  { value: 'corporate_5', label: '법인 5인' },
  { value: 'corporate_10', label: '법인 10인' },
  { value: 'corporate_14', label: '법인 14인' },
  { value: 'corporate_15_plus', label: '법인 15인 이상' },
  { value: 'corporate_25', label: '법인 25인' },
  { value: 'corporate_27', label: '법인 27인' },
  { value: 'personal', label: '개인카드' },
] as const;

// ===== 결제일 옵션 =====
export const PAYMENT_DAY_OPTIONS = [
  { value: '1', label: '매월 1일' },
  { value: '5', label: '매월 5일' },
  { value: '10', label: '매월 10일' },
  { value: '14', label: '매월 14일' },
  { value: '15', label: '매월 15일' },
  { value: '20', label: '매월 20일' },
  { value: '25', label: '매월 25일' },
  { value: '27', label: '매월 27일' },
] as const;

// ===== 날짜 프리셋 =====
export const DATE_PRESETS = [
  { label: '이번달', value: 0 },
  { label: '기본 날짜', value: -1 },
  { label: 'D-2일', value: -2 },
  { label: 'D-3일', value: -3 },
  { label: 'D-4일', value: -4 },
  { label: 'D-5일', value: -5 },
] as const;

// ===== 카드 사용자 정보 =====
export interface CardUser {
  id: string;
  departmentId: string;
  departmentName: string;
  employeeId: string;
  employeeName: string;
  positionId: string;
  positionName: string;
}

// ===== 카드 정보 =====
export interface Card {
  id: string;
  cardCompany: CardCompany | string;
  cardType: string;
  cardNumber: string;
  cardName: string;
  alias: string;
  expiryDate: string;
  csv: string;
  paymentDay: string;
  pinPrefix: string;
  totalLimit: number;
  usedAmount: number;
  remainingLimit: number;
  status: CardStatus;
  isManual: boolean;
  user?: CardUser;
  memo: string;
  createdAt: string;
  updatedAt: string;
}

// ===== 카드 폼 데이터 (Zod 스키마) =====
export const cardFormSchema = z.object({
  cardCompany: z.string().min(1, '카드사를 선택해주세요'),
  cardType: z.string(),
  cardNumber: z.string(),
  cardName: z.string(),
  alias: z.string(),
  expiryDate: z.string().max(4),
  csv: z.string().max(4),
  paymentDay: z.string(),
  pinPrefix: z.string(),
  totalLimit: z.number().min(0, '0 이상 입력하세요'),
  usedAmount: z.number().min(0, '0 이상 입력하세요'),
  remainingLimit: z.number().min(0, '0 이상 입력하세요'),
  status: z.enum(['active', 'suspended']),
  userId: z.string().optional(),
  departmentId: z.string().optional(),
  positionId: z.string().optional(),
  memo: z.string(),
});

export type CardFormData = z.infer<typeof cardFormSchema>;

// ===== 통계 =====
export interface CardStats {
  totalCount: number;
  upcomingPayment: number;
  totalLimit: number;
  remainingLimit: number;
}

// ===== 리스트 필터 =====
export interface CardListFilter {
  startDate: string;
  endDate: string;
  cardCompany: string;
  status: string;
  search: string;
  page: number;
}
