import request from '@/config/axios'

export interface YearKValueVO {
  id?: number
  kYear?: number
  kValue?: number
  remark?: string
  enabledFlag?: boolean
  createTime?: string
}

export interface YearKValuePageReqVO extends PageParam {
  kYear?: number
  enabledFlag?: boolean
}

const normalizeYearKValue = (data: any): YearKValueVO => ({
  id: data?.id,
  kYear: data?.kYear ?? data?.kyear,
  kValue: data?.kValue ?? data?.kvalue,
  remark: data?.remark,
  enabledFlag: data?.enabledFlag ?? data?.enabledflag,
  createTime: data?.createTime ?? data?.createtime
})

export const getYearKValuePage = async (params: YearKValuePageReqVO) => {
  const data = await request.get({ url: '/tjt/year-k-value/page', params })
  return {
    ...data,
    list: Array.isArray(data?.list) ? data.list.map(normalizeYearKValue) : []
  }
}

export const getYearKValue = async (id: number) => {
  const data = await request.get({ url: '/tjt/year-k-value/get', params: { id } })
  return normalizeYearKValue(data)
}

export const createYearKValue = (data: YearKValueVO) => {
  return request.post({ url: '/tjt/year-k-value/create', data })
}

export const updateYearKValue = (data: YearKValueVO) => {
  return request.put({ url: '/tjt/year-k-value/update', data })
}

export const deleteYearKValue = (id: number) => {
  return request.delete({ url: '/tjt/year-k-value/delete', params: { id } })
}
