import type { SalaryRecord, SalaryQuery, SalaryCreateRequest } from '@/views/salary-management/types'
import http from '@/utils/http'

const BASE_URL = '/salary'

// 获取工资单列表
export const getSalaryList = (query?: SalaryQuery) => {
  return http.get<PageRes<SalaryRecord[]>>(`${BASE_URL}/list`, query)
}

// 获取工资单详情
export const getSalaryDetail = (id: string) => {
  return http.get<SalaryRecord>(`${BASE_URL}/${id}`)
}

// 创建工资单
export const createSalary = (data: SalaryCreateRequest) => {
  return http.post<SalaryRecord>(`${BASE_URL}`, data)
}

// 更新工资单
export const updateSalary = (id: string, data: Partial<SalaryRecord>) => {
  return http.put<SalaryRecord>(`${BASE_URL}/${id}`, data)
}

// 删除工资单
export const deleteSalary = (id: string) => {
  return http.del<boolean>(`${BASE_URL}/${id}`)
}

// 提交审批
export const submitApproval = (id: string) => {
  return http.post<boolean>(`${BASE_URL}/${id}/submit`)
}

// 审批工资单
export const approveSalary = (id: string, data: { status: string; comment?: string }) => {
  return http.put<boolean>(`${BASE_URL}/${id}/approve`, data)
}

// 导出工资单
export const exportSalary = (id: string, format: 'excel' | 'pdf' = 'excel') => {
  return http.download(`${BASE_URL}/${id}/export`, { format })
}

// 批量导出
export const exportSalaryBatch = (ids: string[], format: 'excel' | 'pdf' = 'excel') => {
  return http.download(`${BASE_URL}/export/batch`, { ids, format })
}

// 获取实习生配置
export const getInternConfig = () => {
  return http.get<any>(`${BASE_URL}/config/intern`)
}

// 获取员工列表
export const getEmployeeList = (type?: string) => {
  return http.get<any[]>(`${BASE_URL}/employees`, { type })
}

// 获取项目列表
export const getProjectList = () => {
  return http.get<any[]>(`${BASE_URL}/projects`)
}
