import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace MesQcInspectionLedgerApi {
  /** MES 检测结果台账（一行一个检测项结果；检验单未录入检测项时该组字段为空） */
  export interface Ledger {
    qcType?: number; // 分类（检验类型）：1 来料检验 / 2 过程检验 / 3 出货检验 / 4 退货检验
    qcId?: number; // 检验单 ID
    code?: string; // 检验单编号
    name?: string; // 检验单名称
    status?: number; // 单据状态
    itemId?: number; // 物料编号
    itemCode?: string; // 物料编码
    itemName?: string; // 物料名称
    itemSpecification?: string; // 规格型号
    unitName?: string; // 计量单位名称
    batchNo?: string; // 批次号
    checkQuantity?: number; // 检测数量
    qualifiedQuantity?: number; // 合格数量
    unqualifiedQuantity?: number; // 不合格数量
    checkResult?: number; // 检测结果
    inspectDate?: string; // 检测日期
    inspectorUserId?: number; // 检测人员编号
    inspectorName?: string; // 检测人员昵称
    indicatorId?: number; // 检测项编号
    indicatorName?: string; // 检测项名称
    indicatorValue?: string; // 检测值（实测值）
    indicatorRemark?: string; // 检测项备注
    judgementBasis?: string; // 判定依据，如 10~20、≤20、≥10、标准值 15
    remark?: string; // 检验单备注
  }
}

/** 查询检测结果台账分页（四类检验单统一查询） */
export function getInspectionLedgerPage(params: PageParam) {
  return requestClient.get<PageResult<MesQcInspectionLedgerApi.Ledger>>(
    '/mes/qc/inspection-ledger/page',
    { params },
  );
}

/** 导出检测结果台账 */
export function exportInspectionLedger(params: Record<string, unknown>) {
  return requestClient.download('/mes/qc/inspection-ledger/export-excel', {
    params,
  });
}
