import type * as T from './type'
import http from '@/utils/http'

const BASE_URL = '/performance'

/* ===== 维度 ===== */
export const getDimensionList = () => http.get<T.DimensionResp[]>(`${BASE_URL}/dimension`)

export const addDimension = (data: T.DimensionAddReq) =>
  http.post<boolean>(`${BASE_URL}/dimension`, data)

export const updateDimension = (id: string, data: T.DimensionUpdateReq) =>
  http.put<boolean>(`${BASE_URL}/dimension/${id}`, data)

export const deleteDimension = (id: string) =>
  http.del<boolean>(`${BASE_URL}/dimension/${id}`)

/** 维度详情（RuleDrawer.vue 需要） */
export const getDimensionDetail = (id: string) =>
  http.get<T.DimensionResp>(`${BASE_URL}/dimension/${id}`)

/* ===== 细则 ===== */
export const getRuleList = (dimensionId: string) =>
  http.get<T.RuleResp[]>(`${BASE_URL}/rule`, { dimensionId })

export const addRule = (data: T.RuleAddReq) =>
  http.post<boolean>(`${BASE_URL}/rule`, data)

export const updateRule = (id: string, data: T.RuleUpdateReq) =>
  http.put<boolean>(`${BASE_URL}/rule/${id}`, data)

export const deleteRule = (id: string) =>
  http.del<boolean>(`${BASE_URL}/rule/${id}`)

/** 细则详情（RuleDrawer.vue 需要） */
export const getRuleDetail = (id: string) =>
  http.get<T.RuleResp>(`${BASE_URL}/rule/${id}`)

/* ===== 周期 ===== */
export const getPeriodList = () => http.get<T.PeriodResp[]>(`${BASE_URL}/period`)
export const addPeriod = (data: T.PeriodResp) => http.post<boolean>(`${BASE_URL}/period`, data)
export const deletePeriod = (id: string) => http.del<boolean>(`${BASE_URL}/period/${id}`)
export const updataPeriod = (id: string, data: T.PeriodResp) => http.post<boolean>(`${BASE_URL}/period/${id}`, data)

/* ===== 评估 ===== */
export const startEvaluate = (data: T.EvaluateReq) =>
  http.post<boolean>(`${BASE_URL}/evaluate`, data)

export const getEvaluatePage = (query?: T.EvaluateQuery) =>
  http.get<PageRes<T.EvaluateResp[]>>(`${BASE_URL}/evaluate/page`, query)
// 同样的修改和删除评估接口

/** 员工查看自己的绩效 */
export const getMyEvaluate = (query?: T.EvaluateQuery) =>
  http.get<PageRes<T.EvaluateResp[]>>(`${BASE_URL}/evaluate/my`, query)

/* ===== 反馈 ===== */
export const submitFeedback = (data: T.FeedbackReq) =>
  http.post<boolean>(`${BASE_URL}/feedback`, data)
