import { type ParameterInputObject } from '@/components/ResourceSelect';
import { type NodeStatus } from '@/types';
import { type FormParameter } from './components/CreateForm/utils';

// 操作类型
export enum OperationType {
  Create = 'Create', // 创建
  Update = 'Update', // 更新
}

// 表单数据
export type FormData = {
  name: string; // 实验名称
  description: string; // 实验描述
  code_config: ParameterInputObject; // 代码
  dataset: ParameterInputObject; // 数据集
  model: ParameterInputObject; // 模型
  image: ParameterInputObject; // 镜像
  main_py: string; // 主函数代码文件
  metric: string; // 指标
  mode: string; // 优化方向
  search_alg?: string; // 搜索算法
  scheduler?: string; // 调度算法
  num_samples: number; // 总试验次数
  max_t: number; // 单次试验最大时间
  min_samples_required: number; // 计算中位数的最小试验数
  computing_resource_id: number; // 资源规格
  parameters: FormParameter[];
  points_to_evaluate: { [key: string]: any }[];
};

export type HyperParameterData = {
  id: number;
  progress: number;
  run_state: string;
  state: number;
  create_by?: string;
  create_time?: string;
  update_by?: string;
  update_time?: string;
  status_list: string; // 最近五次运行状态
} & FormData;

// 实验实例
export type HyperParameterInstanceData = {
  id: number;
  ray_id: number;
  result_path: string;
  result_txt: string;
  state: number;
  status: string;
  node_status: string;
  node_result: string;
  param: string;
  source: string | null;
  argo_ins_name: string;
  argo_ins_ns: string;
  create_time: string;
  update_time: string;
  finish_time: string;
  nodeStatus?: NodeStatus; // json之后的节点状态
  trial_list?: HyperParameterTrial[];
  file_list?: HyperParameterFile[];
};

export type HyperParameterTrial = {
  trial_id: string;
  training_iteration?: number;
  time?: number;
  status?: string;
  config?: Record<string, any>;
  metric_analysis?: Record<string, any>;
  metric: string;
  file: HyperParameterFile;
  is_best?: boolean;
};

export type HyperParameterFile = {
  name: string;
  size: string;
  url: string;
  isFile: boolean;
  children: HyperParameterFile[];
};
