import http from '@/utils/http'
import { AppDispatch } from '..'

/**
 *课程预约设置-新版-列表
 */

export const A2N_APIgetList = (time?: string, isList?: boolean): any => {
  if (!time && !isList) return http.get(`cms/subjectBook/list`)
  else {
    let url = 'cms/subjectBook/list'
    if (time) url += `?date=${time}-01`

    return async (dispatch: AppDispatch) => {
      const res = await http.get(url)
      if (res.code === 0) {
        dispatch({ type: 'A2N/getList', payload: res.data || [] })
      }
    }
  }
}

/**
 * 课程预约设置-新版-详情
 */
export const A2N_APIsave = (data: any) => {
  return http.post('cms/subjectBook/save', data)
}

/**
 * 课程预约设置-新版-新增时段
 */
export const A2N_APIsavePeriod = (data: any) => {
  return http.post('cms/subjectBook/time/save', data)
}
