// 공통코드 관련 타입 정의

export interface CodeCategory {
  category_code: string;
  category_name: string;
  category_name_eng?: string | null;
  description?: string | null;
  sort_order: number;
  is_active: string;
  created_date?: string | null;
  created_by?: string | null;
  updated_date?: string | null;
  updated_by?: string | null;
}

// CategoryInfo는 CodeCategory의 별칭
export type CategoryInfo = CodeCategory;

export interface CodeInfo {
  // 백엔드 응답 필드 (변환된 형태)
  codeValue?: string;
  codeName?: string;
  codeNameEng?: string | null;
  description?: string | null;
  sortOrder?: number;
  isActive?: string | boolean;
  useYn?: string;
  parentCodeValue?: string | null; // 계층구조: 부모 코드값
  depth?: number; // 계층구조: 깊이 (1, 2, 3단계)

  // 기존 필드 (하위 호환성을 위해 유지)
  code_category?: string;
  code_value?: string;
  code_name?: string;
  code_name_eng?: string | null;
  sort_order?: number;
  is_active?: string;
  parent_code_value?: string | null; // 계층구조: 부모 코드값
  created_date?: string | null;
  created_by?: string | null;
  updated_date?: string | null;
  updated_by?: string | null;
  
  // 트리 구조용
  children?: CodeInfo[];
}

export interface CreateCategoryRequest {
  categoryCode: string;
  categoryName: string;
  categoryNameEng?: string;
  description?: string;
  sortOrder?: number;
}

export interface UpdateCategoryRequest {
  categoryName?: string;
  categoryNameEng?: string;
  description?: string;
  sortOrder?: number;
  isActive?: "Y" | "N"; // 백엔드에서 기대하는 문자열 타입
}

export interface CreateCodeRequest {
  codeValue: string;
  codeName: string;
  codeNameEng?: string;
  description?: string;
  sortOrder?: number;
  parentCodeValue?: string; // 계층구조: 부모 코드값
}

export interface UpdateCodeRequest {
  codeName?: string;
  codeNameEng?: string;
  description?: string;
  sortOrder?: number;
  isActive?: "Y" | "N"; // 백엔드에서 기대하는 문자열 타입
  parentCodeValue?: string; // 계층구조: 부모 코드값
}

export interface CodeOption {
  value: string;
  label: string;
  labelEng?: string | null;
}

export interface ReorderCodesRequest {
  codes: Array<{
    codeValue: string;
    sortOrder: number;
  }>;
}

export interface GetCategoriesQuery {
  search?: string;
  isActive?: boolean;
  page?: number;
  size?: number;
}

export interface GetCodesQuery {
  search?: string;
  isActive?: boolean;
  page?: number;
  size?: number;
}

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