import { IQueryCommon, IRes, IResult } from '@/api/common'
import axios from '@/utils/request'
import { base, ISection } from './common'

const uris = {
  base: `${base}/partition`,
  page: `${base}/partition/page`,
  del: `${base}/partition/deleteByIds`
}

export const addSection = (data: Omit<ISection, 'id'>) =>
  axios.request<IRes<boolean>>({ url: uris.base, method: 'post', data })

export const deleteSection = (id: string) =>
  axios.request<IRes<boolean>>({ url: `${uris.base}/${id}`, method: 'delete' })

export const updateSection = (data: ISection) => axios.request<IRes<boolean>>({ url: uris.base, method: 'put', data })

export const getSection = (id: string) => axios.request<IResult<ISection>>({ url: `${uris.base}/${id}`, method: 'get' })

export const sectionPage = (params: Partial<ISection & IQueryCommon>) =>
  axios.request<IRes<ISection[]>>({ url: uris.page, method: 'get', params })

export const deleteSectionBatch = (ids: string) =>
  axios.request<IRes<boolean>>({ url: uris.del, method: 'delete', params: { ids } })
