export interface ConnectionType {
  id: "data_save" | "external_call";
  label: string;
  description: string;
  icon: React.ReactNode;
}

export interface FieldMapping {
  id: string;
  fromField: ColumnInfo;
  toField: ColumnInfo;
  transformRule?: string;
  isValid: boolean;
  validationMessage?: string;
}

export interface ColumnInfo {
  name: string;
  type: string;
  nullable: boolean;
  primaryKey: boolean;
  foreignKey?: boolean;
  defaultValue?: any;
  columnName?: string;
  displayName?: string;
  webType?: string;
}

export interface TableInfo {
  name: string;
  schema: string;
  columns: ColumnInfo[];
  rowCount?: number;
}

export interface Connection {
  id: string;
  name: string;
  type: string;
  host: string;
  port: number;
  database: string;
  username: string;
  tables: TableInfo[];
}

export interface MappingStats {
  totalMappings: number;
  validMappings: number;
  invalidMappings: number;
  missingRequiredFields: number;
  estimatedRows: number;
  actionType: "INSERT" | "UPDATE" | "DELETE";
}

export interface ValidationError {
  field: string;
  message: string;
  severity: "error" | "warning" | "info";
}

export interface DataConnectionState {
  // 기본 설정
  connectionType: "data_save" | "external_call";
  currentStep: 1 | 2 | 3;

  // 연결 정보
  fromConnection?: Connection;
  toConnection?: Connection;
  fromTable?: TableInfo;
  toTable?: TableInfo;

  // 매핑 정보
  fieldMappings: FieldMapping[];
  mappingStats: MappingStats;

  // 액션 설정
  actionType?: "insert" | "update" | "delete" | "upsert";
  actionConditions: any[];
  actionGroups: Array<{ actions: Array<{ fieldMappings?: FieldMapping[] }> }>;
  controlConditions: any[];
  fromColumns?: any[];
  toColumns?: any[];

  // UI 상태
  selectedMapping?: string;
  isLoading: boolean;
  validationErrors: ValidationError[];
}

export interface DataConnectionActions {
  saveMappings: () => Promise<void>;
  testExecution: () => Promise<void>;
  setConnectionType: (type: "data_save" | "external_call") => void;
  updateMapping: (id: string, mapping: Partial<FieldMapping>) => void;
  deleteMapping: (id: string) => void;
  setActionType: (type: string) => void;
  setActionConditions: (conditions: any[]) => void;
  loadColumns: () => void;
  addControlCondition: () => void;
  updateControlCondition: (index: number, condition: any) => void;
  deleteControlCondition: (index: number) => void;
}

export interface LeftPanelProps {
  state: DataConnectionState;
  actions: DataConnectionActions;
}

export interface MappingDetailListProps {
  mappings: FieldMapping[];
  selectedMapping?: string;
  onSelectMapping: (id: string) => void;
  onUpdateMapping: (id: string, mapping: Partial<FieldMapping>) => void;
  onDeleteMapping: (id: string) => void;
}

export interface SingleAction {
  id: string;
  name?: string;
  actionType: "insert" | "update" | "delete" | "upsert";
  isEnabled: boolean;
  conditions: any[];
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  fieldMappings?: any[];
}

export interface ActionGroup {
  id: string;
  name?: string;
  logicalOperator: "AND" | "OR";
  isEnabled: boolean;
  actions: SingleAction[];
}

export interface FieldMappingCanvasProps {
  fromFields: any[];
  toFields: any[];
  mappings: FieldMapping[];
  onCreateMapping: (fromField: any, toField: any) => void;
  onDeleteMapping: (mappingId: string) => void;
}

export interface RightPanelProps {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  state: any;
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  actions: any;
}