import request from '@/utils/request'

// 运单查询相关接口
export const trackingAPI = {
  // 查询运单信息
  getPackageInfo: (trackingNumber: string) => 
    request.get('/api/tracking/${trackingNumber}'),
  
  // 获取已寄出的包裹列表
  getSentPackages: () => 
    request.get('/api/tracking/sent'),
  
  // 获取已收到的包裹列表
  getReceivedPackages: () => 
    request.get('/api/tracking/received')
}

// 投诉相关接口
export const complaintAPI = {
  // 提交投诉
  submitComplaint: (data: {
    orderNumber: string,
    reason: string,
    description: string,
    contact: string
  }) => request.post('/api/complaints', data)
}

// 寄件相关接口
export const deliveryAPI = {
  // 提交寄件信息
  submitDelivery: (data: {
    sender: {
      name: string,
      phone: string,
      province: string[],
      address: string,
      company?: string
    },
    receiver: {
      name: string,
      phone: string,
      province: string[],
      address: string,
      company?: string
    },
    sendType: number
  }) => request.post('/api/delivery', data),

  // 获取地址簿
  getAddressBook: () => 
    request.get('/api/address-book')
}

// 反馈相关接口
export const feedbackAPI = {
  // 提交反馈
  submitFeedback: (data: {
    title: string,
    content: string,
    contact?: string
  }) => request.post('/api/feedback', data)
}

// 用户资料相关接口
export const profileAPI = {
  // 获取用户信息
  getUserProfile: () => 
    request.get('/api/user/profile'),
  
  // 更新用户信息
  updateProfile: (data: {
    name: string,
    email: string,
    phone: string,
    gender: string,
    birthday: string,
    address: string
  }) => request.put('/api/user/profile', data),

  // 更新头像
  updateAvatar: (formData: FormData) => 
    request.post('/api/user/avatar', formData),

  // 地址管理相关
  getAddresses: () => 
    request.get('/api/user/addresses'),
  
  addAddress: (data: {
    name: string,
    address: string,
    phone: string
  }) => request.post('/api/user/addresses', data),
  
  updateAddress: (id: number, data: {
    name: string,
    address: string,
    phone: string
  }) => request.put(`/api/user/addresses/${id}`, data),
  
  deleteAddress: (id: number) => 
    request.delete(`/api/user/addresses/${id}`)
}
