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

const uris = {
  base: `${base}/standardtargetp`,
  page: `${base}/standardtargetp/page`,
  del: `${base}/standardtargetp/deleteByIds`,
  param: {
    base: `${base}/targetthresholdp`,
    page: `${base}/targetthresholdp/page`,
    del: `${base}/targetthresholdp/deleteByIds`
  }
}

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

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

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

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

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

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

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

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

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

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

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

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