/**
 * 백엔드 데이터 매핑 관련 타입 정의
 */

export type DataDirection = "none" | "inbound" | "outbound" | "bidirectional";
export type InsertMode = "insert" | "upsert" | "update";
export type TransformType = "none" | "constant" | "format" | "function";
export type DataType = "string" | "number" | "boolean" | "date" | "json";

export interface FieldTransform {
  type: TransformType;
  value?: any;
  format?: string;
  functionName?: string;
}

export interface FieldMapping {
  id: string;
  sourceField: string;
  targetField: string;
  dataType: DataType;
  transform?: FieldTransform;
  required?: boolean;
  defaultValue?: any;
}

export interface InboundMapping {
  targetTable: string;
  targetSchema?: string;
  fieldMappings: FieldMapping[];
  insertMode: InsertMode;
  keyFields?: string[];
  batchSize?: number;
}

export interface OutboundMapping {
  sourceTable: string;
  sourceSchema?: string;
  sourceFilter?: string;
  fieldMappings: FieldMapping[];
  triggerCondition?: string;
}

export interface DataMappingConfig {
  direction: DataDirection;
  inboundMapping?: InboundMapping;
  outboundMapping?: OutboundMapping;
}

export interface TableInfo {
  name: string;
  schema?: string;
  displayName?: string;
  fields: FieldInfo[];
}

export interface FieldInfo {
  name: string;
  dataType: DataType;
  nullable: boolean;
  isPrimaryKey?: boolean;
  displayName?: string;
  description?: string;
}

export interface DataMappingResult {
  success: boolean;
  direction: DataDirection;
  recordsProcessed?: number;
  recordsInserted?: number;
  recordsUpdated?: number;
  recordsSkipped?: number;
  errors?: string[];
  executionTime: number;
  timestamp: string;
}

export interface MappingValidationResult {
  isValid: boolean;
  errors: string[];
  warnings: string[];
}
