import axiosInstance from '../../utils/axios';

export interface PlanQuery {
  pageNo?: number;
  pageSize?: number;
  current?: number;
  size?: number;
  /** 物资柜维度筛选（若后端支持） */
  cabinetId?: number;
  planName?: string;
  /** 与旧版 inspectionplan 一致：检察员昵称 */
  checkUserName?: string;
  /** 检查计划状态（字典 CHECKING_STATUS，多为字符串） */
  status?: string;
  planStatus?: number;
  startTime?: Date | string;
  endTime?: Date | string;
  [key: string]: any;
}

export interface PlanVO {
  planId?: number;
  planName: string;
  planStatus?: number;
  startTime?: Date | string;
  endTime?: Date | string;
  checkCycle?: number;
  checkCycleUnit?: string;
  remark?: string;
  [key: string]: any;
}

export interface AutoConfigVO {
  configCode: string;
  configValue: string;
  configName: string;
  configType?: number;
  status?: number;
}

/** 自动创建检查计划配置（POST /updateAutomaticConfig，与旧版 inspectionplan 表单字段一致） */
export interface PlanAutomaticCreateConfig {
  planFrequency?: string | null;
  planDate?: string | number | null;
  checkUserId?: number | string | null;
  startStatus?: number;
  templateCode?: string;
}

export const materialPlanApi = {
  listPlan: (params: PlanQuery) =>
    axiosInstance.get('/iscs/materials-check-plan/getMaterialsCheckPlanPage', { params }),
  getPlanInfo: (id: number) =>
    axiosInstance.get('/iscs/materials-check-plan/selectMaterialsCheckPlanById', { params: { id } }),
  addPlan: (data: PlanVO) =>
    axiosInstance.post('/iscs/materials-check-plan/insertMaterialsCheckPlan', data),
  updatePlan: (data: PlanVO) =>
    axiosInstance.put('/iscs/materials-check-plan/updateMaterialsCheckPlan', data),
  deletePlan: (ids: number) =>
    axiosInstance.delete('/iscs/materials-check-plan/deleteMaterialsCheckPlanList', { params: { ids } }),
  getCheckPlanCabinetList: (params: PlanQuery) =>
    axiosInstance.get('/iscs/materials-plan-cabinet/getMaterialsPlanCabinetPage', { params }),
  updateAutomaticConfig: (data: PlanAutomaticCreateConfig | AutoConfigVO) =>
    axiosInstance.post('/iscs/mail-notify-config/updateAutomaticConfig', data),
  /** 旧版使用 templateCode（如 test_01）；部分环境认 configCode，可同时传 */
  selectIsMailNotifyConfigByCode: (params: { configCode?: string; templateCode?: string }) =>
    axiosInstance.get('/iscs/mail-notify-config/selectMailNotifyConfigByCode', { params }),
};
