import request from "@/utils/request";

const API_PATH = "/business/mec";

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

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

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

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

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

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

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

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

  // 导入
  importBizMec(body: FormData) {
    return request<ApiResponse>({
      url: `${API_PATH}/import`,
      method: "post",
      data: body,
      headers: { "Content-Type": "multipart/form-data" },
    });
  },
};

export default BizMecAPI;

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

// 列表查询参数
export interface BizMecPageQuery extends PageQuery {
  crane_no?: string;
  mec_no?: string;
  mec_category?: string;
  mec_type?: string;
  status?: string;
  created_time?: string[];
  updated_time?: string[];
}

// 列表展示项
export interface BizMecTable extends BaseType{
  crane_no?: string;
  crane_name?: string;
  mec_no?: string;
  mec_category?: string;
  mec_type?: string;
  hoist_weight?: string;
  hoist_height?: string;
  hoist_speed?: string;
  rope_count?: string;
  rope_max_pull?: string;
  rope_diameter?: string;
  rope_model?: string;
  car_speed?: string;
  wheel_span?: string;
  track_span?: string;
  wheel_pressure?: string;
  track_model?: string;
  track_diameter?: string;
  track_count?: string;
  word_system?: string;
  reducer_model?: string;
  reducer_trans_ratio?: string;
  reducer_total_trans_ratio?: string;
  motor_model?: string;
  motor_voltage?: string;
  motor_current?: string;
  motor_power?: string;
  motor_speed?: string;
  motor_count?: string;
  bradk_model?: string;
  brake_torque?: string;
  brake_wheel_diameter?: string;
  brake_count?: string;
  sort?: string;
  hoist_weight_var_code?: string;
  stroke_var_code?: string;
  is_canvas_show?: string;
  is_canvas_move?: string;
  gear_select_var_codes?: string;
  vib_gear_value?: string;
  created_by?: creatorType;
  updated_by?: updatorType;
}

// 新增/修改/详情表单参数
export interface BizMecForm extends BaseFormType{
  crane_no?: string;
  mec_no?: string;
  mec_category?: string;
  mec_type?: string;
  hoist_weight?: string;
  hoist_height?: string;
  sort?: string;
  hoist_weight_var_code?: string;
  stroke_var_code?: string;
  is_canvas_show?: string;
  is_canvas_move?: string;
}
