import request from '@/axios';

// ==================== 扣分项管理接口 ====================

/**
 * 扣分项分页查询
 * @param {Number} current - 当前页,默认1
 * @param {Number} size - 每页条数,默认10
 * @param {Object} params - 查询参数
 * @param {Number} params.projectId - 项目ID
 * @param {String} params.itemName - 扣分项名称(可选)
 */
export const getDeductionList = (current, size, params) => {
  return request({
    url: '/api/blade-martial/deductionItem/list',
    method: 'get',
    params: {
      current,
      size,
      ...params
    }
  })
}

/**
 * 获取扣分项详情
 * @param {Number} id - 扣分项ID
 */
export const getDeductionDetail = (id) => {
  return request({
    url: '/api/blade-martial/deductionItem/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增扣分项
 * @param {Object} data - 扣分项数据
 * @param {Number} data.projectId - 项目ID
 * @param {String} data.itemName - 扣分项名称
 * @param {Number} data.deductionPoints - 扣分值
 * @param {String} data.description - 描述说明
 * @param {Number} data.sortOrder - 排序序号
 */
export const addDeduction = (data) => {
  return request({
    url: '/api/blade-martial/deductionItem/submit',
    method: 'post',
    data
  })
}

/**
 * 修改扣分项
 * @param {Object} data - 扣分项数据
 */
export const updateDeduction = (data) => {
  return request({
    url: '/api/blade-martial/deductionItem/submit',
    method: 'post',
    data
  })
}

/**
 * 删除扣分项
 * @param {String} ids - 扣分项ID,多个用逗号分隔
 */
export const removeDeduction = (ids) => {
  return request({
    url: '/api/blade-martial/deductionItem/remove',
    method: 'post',
    params: { ids }
  })
}

/**
 * 获取项目的扣分项列表（不分页）
 * @param {Number} projectId - 项目ID
 */
export const getDeductionsByProject = (projectId) => {
  return request({
    url: '/api/blade-martial/deductionItem/list-by-project',
    method: 'get',
    params: { projectId }
  })
}

/**
 * 克隆扣分项
 * @param {Object} data - 克隆数据
 * @param {Number} data.sourceProjectId - 源项目ID
 * @param {Number} data.targetProjectId - 目标项目ID
 */
export const cloneDeductions = (data) => {
  return request({
    url: '/api/blade-martial/deductionItem/clone',
    method: 'post',
    data
  })
}

/**
 * 更新扣分项排序
 * @param {Array} sortData - 排序数据数组 [{id, sortOrder}, ...]
 */
export const updateDeductionOrder = (sortData) => {
  return request({
    url: '/api/blade-martial/deductionItem/update-order',
    method: 'post',
    data: sortData
  })
}

/**
 * 导出扣分项模板
 */
export const exportDeductionTemplate = () => {
  return request({
    url: '/api/blade-martial/deductionItem/export-template',
    method: 'get',
    responseType: 'blob'
  })
}

/**
 * 导出扣分项列表
 * @param {Object} params - 查询参数
 */
export const exportDeductions = (params) => {
  return request({
    url: '/api/blade-martial/deductionItem/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}
