type DataTypeName =
  | 'CSV文件'
  | 'API接口'
  | 'MySQL数据库'
  | 'Oracle数据库'
  | 'SQL Server数据库'
  | '阿里云API网关'
  | 'PostgreSQL数据库'
  | 'ClickHouse数据库'
  | 'DTable API'
  | '数栈 API';

export type DataType =
  | 'static'
  | 'mysql'
  | 'mssql'
  | 'oracle'
  | 'csv'
  | 'api'
  | 'apiGateway'
  | 'postgresql'
  | 'clickhouse'
  | 'dtInsight'
  | 'dtableapi';

export type Source = {
  data_id: string;
  data_name: string;
  data_type: DataTypeName;
  desc: string;
  create_time: string;
  update_time: string;
  user_id: number;
  baseURL?: string;
}[];

interface SourceBase {
  id: string;
  name: string;
  description: string;
  type: DataType;
  updateAt: string;
}

export interface DTableAPISource extends SourceBase {
  api_key: string;
}

export interface APISource extends SourceBase {
  baseURL: string;
}

export interface APIGatewaySource extends APISource {
  appKey: string;
  appSecret: string;
}

export interface CSVSource extends SourceBase {
  filePath: string;
  encode: 'auto' | 'utf8' | 'gbk';
}

export interface MySQLSource extends SourceBase {
  database: string;
  databaseList: string[];
  host: string;
  port: string;
  user: string;
  password: string;
}

export interface OracleSource extends SourceBase {
  host: string;
  port: string;
  user: string;
  password: string;
  sid: string;
}

export type SourceType = {
  loading: boolean;
  page: number;
  pageSize: number;
  search: string;
  list: Array<
    OracleSource | MySQLSource | CSVSource | APIGatewaySource | APISource | DTableAPISource
  >;
};

export type AddSource = (params: {
  type: DataType;
  filePath: File;
  description: string;
  user?: string;
  host?: string;
  name: string;
  encode?: 'auto' | 'utf8' | 'gbk';
  password?: string;
}) => (dispatch: any, getState: any) => Promise<unknown>;
