import { request } from '.'

// 定义结伴游相关类型
export interface Travel {
  id: number
  title: string
  description: string
  start_date: string
  end_date: string
  destination: string
  max_participants: number
  current_participants: number
  price: number
  status: string
  created_at: string
  updated_at: string
}

export interface TravelQueryParams {
  page?: number
  limit?: number
  title?: string
  destination?: string
  status?: string
  start_date?: string
  end_date?: string
}

export interface TravelCreateData {
  title: string
  description: string
  start_date: string
  end_date: string
  destination: string
  max_participants: number
  price: number
  status?: string
}

export interface TravelUpdateData {
  title?: string
  description?: string
  start_date?: string
  end_date?: string
  destination?: string
  max_participants?: number
  price?: number
  status?: string
}

// 获取结伴游列表
export const getTravels = (params?: TravelQueryParams) =>
  request.get<{ success: boolean; code: number; message: string; data: { travels: Travel[]; pagination: any } }>('/travels', { params })

// 获取结伴游详情
export const getTravel = (id: number) =>
  request.get<{ success: boolean; code: number; message: string; data: { travel: Travel } }>(`/travels/${id}`)

// 创建结伴游
export const createTravel = (data: TravelCreateData) =>
  request.post<{ success: boolean; code: number; message: string; data: { travel: Travel } }>('/travels', data)

// 更新结伴游
export const updateTravel = (id: number, data: TravelUpdateData) =>
  request.put<{ success: boolean; code: number; message: string; data: { travel: Travel } }>(`/travels/${id}`, data)

// 删除结伴游
export const deleteTravel = (id: number) =>
  request.delete<{ success: boolean; code: number; message: string }>(`/travels/${id}`)

// 更新结伴游状态
export const updateTravelStatus = (id: number, status: string) =>
  request.put<{ success: boolean; code: number; message: string }>(`/travels/${id}/status`, { status })

// 获取结伴游计划列表
export const getTravelPlans = (params?: TravelQueryParams) =>
  request.get<{ success: boolean; code: number; message: string; data: { travels: Travel[]; pagination: any } }>('/travel-plans', { params })

// 关闭结伴游计划
export const closeTravelPlan = (id: number) =>
  request.put<{ success: boolean; code: number; message: string }>(`/travel-plans/${id}/close`)

export default {
  getTravels,
  getTravel,
  createTravel,
  updateTravel,
  deleteTravel,
  updateTravelStatus,
  getTravelPlans,
  closeTravelPlan
}