import request from "@/utils/request";
import { A } from "vue-router/dist/router-CWoNjPRp.mjs";

const API_PATH = "/business/vardict";

const BizVarDictAPI = {
  // 列表查询
  listBizVarDict(query: BizVarDictPageQuery) {
    return request<ApiResponse<PageResult<BizVarDictTable[]>>>({
      url: `${API_PATH}/list`,
      method: "get",
      params: query,
    });
  },

  listBizVarDictAlarms(query: BizVarDictPageQuery) {
    return request<ApiResponse<BizVarDictTable[]>>({
      url: `${API_PATH}/list_alarms`,
      method: "get",
      params: query,
    });
  },

  listBizVarDictAnalog(query: BizVarDictPageQuery) {
    return request<ApiResponse<BizVarDictTable[]>>({
      url: `${API_PATH}/list_analog`,
      method: "get",
      params: query,
    });
  },

  // 详情查询
  detailBizVarDict(id: number) {
    return request<ApiResponse<BizVarDictTable>>({
      url: `${API_PATH}/detail/${id}`,
      method: "get",
    });
  },

  // 获取变量信息
  varDictMecGroup(crane_no: string) {
    return request<ApiResponse<MecDataItem[]>>({
      url: `${API_PATH}/varDictMecGroup/${crane_no}`,
      method: "get",
    });
  },

  // 新增
  createBizVarDict(body: BizVarDictForm) {
    return request<ApiResponse>({
      url: `${API_PATH}/create`,
      method: "post",
      data: body,
    });
  },

  // 修改（带主键）
  updateBizVarDict(id: number, body: BizVarDictForm) {
    return request<ApiResponse>({
      url: `${API_PATH}/update/${id}`,
      method: "put",
      data: body,
    });
  },

  // 删除（支持批量）
  deleteBizVarDict(ids: number[]) {
    return request<ApiResponse>({
      url: `${API_PATH}/delete`,
      method: "delete",
      data: ids,
    });
  },

  // 批量启用/停用
  batchBizVarDict(body: BatchType) {
    return request<ApiResponse>({
      url: `${API_PATH}/available/setting`,
      method: "patch",
      data: body,
    });
  },

  // 导出
  exportBizVarDict(query: BizVarDictPageQuery) {
    return request<Blob>({
      url: `${API_PATH}/export`,
      method: "post",
      data: query,
      responseType: "blob",
    });
  },

  // 下载导入模板
  downloadTemplateBizVarDict() {
    return request<Blob>({
      url: `${API_PATH}/download/template`,
      method: "post",
      responseType: "blob",
    });
  },

  // 导入
  importBizVarDict(body: FormData) {
    return request<ApiResponse>({
      url: `${API_PATH}/import`,
      method: "post",
      data: body,
      headers: { "Content-Type": "multipart/form-data" },
    });
  },
  historyData(query: BizVarDictPageQuery) {
    return request<ApiResponse<PageResult<BizVarDictTable[]>>>({
      url: `${API_PATH}/historyData`,
      method: "get",
      params: query,
    });
  },
  operationRecord(query: BizVarDictPageQuery) {
    return request<ApiResponse<PageResult<BizVarDictTable[]>>>({
      url: `${API_PATH}/operationRecord`,
      method: "get",
      params: query,
    });
  },
  historyAlarm(query: BizVarDictPageQuery) {
    return request<ApiResponse<PageResult<BizVarDictTable[]>>>({
      url: `${API_PATH}/historyAlarm`,
      method: "get",
      params: query,
    });
  },
};

export default BizVarDictAPI;

// ------------------------------
// TS 类型声明
// ------------------------------

// 列表查询参数
export interface BizVarDictPageQuery extends PageQuery {
  crane_no?: string;
  var_code?: string;
  var_name?: string;
  mec_type?: string;
  switch_type?: string;
  gateway_id?: string;
  var_group?: string;
  var_category?: string;
  is_top_show?: string;
  is_save?: string;
  is_overview_top_show?: string;
  is_home_page_show?: string;
  status?: string;
  created_id?: number;
  updated_id?: number;
  created_time?: string[];
  updated_time?: string[];
  order_by?:string;
  data_type?:string;
}

// 列表展示项
export interface BizVarDictTable extends BaseType{
  crane_no?: string;
  crane_name?: string;
  var_code?: string;
  var_name?: string;
  mec_type?: string;
  data_type?: string;
  switch_type?: string;
  addr?: string;
  gateway_id?: string;
  gateway_name?: string;
  var_sort?: string;
  var_group?: string;
  var_category?: string;
  translate?: string;
  device_no?: string;
  is_reverse?: string;
  is_top_show?: string;
  is_save?: string;
  is_calibration?: string;
  is_overview_top_show?: string;
  is_home_page_show?: string;
  is_diagnose?: string;
  is_upload?: string;
  diagnosis_id?: string;
  created_id?: string;
  updated_id?: string;
  created_by?: creatorType;
  updated_by?: updatorType;
  value?:string;
  ts?:string;
  val?:string;
}

// 新增/修改/详情表单参数
export interface BizVarDictForm extends BaseFormType{
  crane_no?: string;
  crane_name?: string;
  var_code?: string;
  var_name?: string;
  mec_type?: string;
  data_type?: string;
  switch_type?: string;
  addr?: string;
  gateway_id?: string;
  gateway_name?: string;
  var_sort?: string;
  var_group?: string;
  var_category?: string;
  translate?: string;
  device_no?: string;
  is_reverse?: string;
  is_top_show?: string;
  is_save?: string;
  is_calibration?: string;
  is_overview_top_show?: string;
  is_home_page_show?: string;
  is_diagnose?: string;
  is_upload?: string;
  diagnosis_id?: string;
}

export interface VarDictMecGroupData{
  mec_type?: string;
  bool_type_list?:BizVarDictTable[]
  gear_list?:BizVarDictTable[]
  number_type_list?:BizVarDictTable[]
}

export interface MecDataItem {
  mec_type: string;
  varList_simple: BizVarDictTable[];
  digital_varList: BizVarDictTable[];
  analog_varList: BizVarDictTable[];
}
