import request from '/@/utils/request'

/**
 * 按月份返回值班表（列表）
 * @param params year, month
 */
export const listByMonth = (params: { year: string | number; month: string | number }) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/listByMonth',
    method: 'get',
    params
  })
}

/**
 * 后台获取某年某月值班表，回显到日历/列表
 * @param params year, month
 */
export const getDutyByMonth = (params: { year: string | number; month: string | number }) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/getDutyByMonth',
    method: 'get',
    params
  })
}

/**
 * 通过 id 查询值班详情
 * @param id
 */
export const getDetail = (id: string) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/detail',
    method: 'get',
    params: { id }
  })
}

/**
 * 新增/批量新增值班
 * @param list 每项 { date: 'YYYY-MM-DD', teacherUserName: '工号', weekType?: 'single'|'double' }
 */
export const saveDuty = (list: Array<{ date: string; teacherUserName: string; weekType?: string }>) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/saveDuty',
    method: 'post',
    data: list
  })
}

/**
 * 一键清空某月值班
 * @param data { year, month }
 */
export const clearDuty = (data: { year: number; month: number }) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/clearDuty',
    method: 'post',
    data
  })
}

/**
 * 清除单个值班（按日期）
 * @param data { days: 'YYYY-MM-DD' }
 */
export const clearOneDuty = (data: { days: string }) => {
  return request({
    url: '/stuwork/psychologicalcounselingduty/clearOneDuty',
    method: 'post',
    data
  })
}
