import request from "@/utils/request";

const API_PATH = "/business/crane";

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

    // 列表查询
  listBizCraneStatus(query: BizCranePageQuery) {
    return request<ApiResponse<PageResult<BizCraneTable[]>>>({
      url: `${API_PATH}/list_status`,
      method: "get",
      params: query,
    });
  },

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

  detailBizCraneforNo(crane_no: number) {
    return request<ApiResponse<BizCraneTable>>({
      url: `${API_PATH}/detailForNo/${crane_no}`,
      method: "get",
    });
  },

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

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

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

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

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

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

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

export default BizCraneAPI;

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

// 列表查询参数
export interface BizCranePageQuery extends PageQuery {
  crane_name?: string;
  crane_no?: string;
  crane_model?: string;
  ip_address?: string;
  status?: string;
  created_id?: number;
  updated_id?: number;
  created_time?: string[];
  updated_time?: string[];
  order_by?: string;
}

// 列表展示项
export interface BizCraneTable extends BaseType{
  crane_name?: string;
  crane_no?: string;
  crane_model?: string;
  work_span?: string;
  work_height?: string;
  ip_address?: string;
  work_status?: string;
  order?: string;
  created_id?: string;
  updated_id?: string;
  created_by?: creatorType;
  updated_by?: updatorType;
}

// 新增/修改/详情表单参数
export interface BizCraneForm extends BaseFormType{
  crane_name?: string;
  crane_no?: string;
  crane_model?: string;
  work_span?: string;
  work_height?: string;
  ip_address?: string;
  order?: string;
}
