import { request } from '.'

// 定义动物相关类型
export interface Animal {
  id: number
  name: string
  species: string
  breed: string
  age: number
  gender: string
  description: string
  image: string
  merchant_id: number
  merchant_name: string
  price: number
  status: string
  created_at: string
  updated_at: string
}

export interface AnimalQueryParams {
  page?: number
  limit?: number
  keyword?: string
  species?: string
  status?: string
  merchant_id?: number
  start_date?: string
  end_date?: string
}

export interface AnimalCreateData {
  name: string
  species: string
  breed: string
  age: number
  gender: string
  description: string
  image: string
  merchant_id: number
  price: number
  status?: string
}

export interface AnimalUpdateData {
  name?: string
  species?: string
  breed?: string
  age?: number
  gender?: string
  description?: string
  image?: string
  merchant_id?: number
  price?: number
  status?: string
}

// 动物认领相关类型
export interface AnimalClaim {
  id: number
  animal_id: number
  animal_name: string
  user_id: number
  user_name: string
  status: string
  reason: string
  created_at: string
  updated_at: string
}

export interface AnimalClaimQueryParams {
  page?: number
  limit?: number
  status?: string
  animal_id?: number
  user_id?: number
}

// 获取动物列表
export const getAnimals = (params?: AnimalQueryParams) =>
  request.get<{ success: boolean; code: number; message: string; data: { animals: Animal[]; pagination: any } }>('/animals', { params })

// 获取动物详情
export const getAnimal = (id: number) =>
  request.get<{ success: boolean; code: number; message: string; data: { animal: Animal } }>(`/animals/${id}`)

// 创建动物
export const createAnimal = (data: AnimalCreateData) =>
  request.post<{ success: boolean; code: number; message: string; data: { animal: Animal } }>('/animals', data)

// 更新动物
export const updateAnimal = (id: number, data: AnimalUpdateData) =>
  request.put<{ success: boolean; code: number; message: string; data: { animal: Animal } }>(`/animals/${id}`, data)

// 删除动物
export const deleteAnimal = (id: number) =>
  request.delete<{ success: boolean; code: number; message: string }>(`/animals/${id}`)

// 更新动物状态
export const updateAnimalStatus = (id: number, status: string) =>
  request.put<{ success: boolean; code: number; message: string }>(`/animals/${id}/status`, { status })

// 获取动物认领列表
export const getAnimalClaims = (params?: AnimalClaimQueryParams) =>
  request.get<{ success: boolean; code: number; message: string; data: { claims: AnimalClaim[]; pagination: any } }>('/animal-claims', { params })

// 批准动物认领
export const approveAnimalClaim = (id: number, remark: string) =>
  request.put<{ success: boolean; code: number; message: string }>(`/animal-claims/${id}/approve`, { remark })

// 拒绝动物认领
export const rejectAnimalClaim = (id: number, remark: string) =>
  request.put<{ success: boolean; code: number; message: string }>(`/animal-claims/${id}/reject`, { remark })

export default {
  getAnimals,
  getAnimal,
  createAnimal,
  updateAnimal,
  deleteAnimal,
  updateAnimalStatus,
  getAnimalClaims,
  approveAnimalClaim,
  rejectAnimalClaim
}