import http from './http'

export const api = {
  register: (payload) => http.post('/auth/register', payload),
  login: (payload) => http.post('/auth/login', payload),
  me: () => http.get('/auth/me'),
  updateMe: (payload) => http.put('/auth/me', payload),

  banners: () => http.get('/public/banners'),
  products: (keyword = '') => http.get('/public/products', { params: { keyword } }),

  customerCart: () => http.get('/customer/cart'),
  customerCartViews: () => http.get('/customer/cart/views'),
  addCart: (payload) => http.post('/customer/cart', payload),
  delCart: (productId) => http.delete(`/customer/cart/${productId}`),
  checkout: (payload) => http.post('/customer/orders/checkout', payload),
  customerBuyNow: (payload) => http.post('/customer/orders/buy-now', payload),
  customerOrders: () => http.get('/customer/orders'),
  refundOrder: (id, payload) => http.put(`/customer/orders/${id}/refund`, payload),
  updateOrderAddress: (id, payload) => http.put(`/customer/orders/${id}/address`, payload),
  deleteOrder: (id) => http.delete(`/customer/orders/${id}`),
  orderLogistics: (id) => http.get(`/customer/orders/${id}/logistics`),
  customerFavorites: () => http.get('/customer/favorites'),
  customerFavoriteViews: () => http.get('/customer/favorites/views'),
  addFavorite: (payload) => http.post('/customer/favorites', payload),
  deleteFavorite: (productId) => http.delete(`/customer/favorites/${productId}`),
  addReview: (payload) => http.post('/customer/reviews', payload),
  orderItems: (orderId) => http.get(`/customer/orders/${orderId}/items`),
  applyMerchant: (payload) => http.post('/customer/merchant-applications', payload),

  merchantOverview: () => http.get('/merchant/overview'),
  merchantProducts: () => http.get('/merchant/products'),
  saveMerchantProduct: (payload) => http.post('/merchant/products', payload),
  deleteMerchantProduct: (id) => http.delete(`/merchant/products/${id}`),
  merchantOrders: () => http.get('/merchant/orders'),
  shipOrder: (id, payload) => http.put(`/merchant/orders/${id}/ship`, payload),
  merchantRefund: (id, payload) => http.put(`/merchant/orders/${id}/refund`, payload),
  merchantReviews: () => http.get('/merchant/reviews'),
  merchantLogistics: () => http.get('/merchant/logistics'),
  merchantInventory: () => http.get('/merchant/inventory'),
  deleteMerchantInventory: (id) => http.delete(`/merchant/inventory/${id}`),

  adminOverview: () => http.get('/admin/overview'),
  adminUsers: () => http.get('/admin/users'),
  adminSaveUser: (payload) => http.post('/admin/users', payload),
  adminDeleteUser: (id) => http.delete(`/admin/users/${id}`),
  adminOrders: () => http.get('/admin/orders'),
  adminUpdateOrder: (id, payload) => http.put(`/admin/orders/${id}`, payload),
  adminOrderRisks: () => http.get('/admin/orders/risk'),
  adminAuditRefund: (id, payload) => http.put(`/admin/orders/${id}/refund-audit`, payload),
  adminAuditShipment: (id, payload) => http.put(`/admin/orders/${id}/ship-audit`, payload),
  adminMerchantApplications: () => http.get('/admin/merchant-applications'),
  adminAuditMerchantApplication: (id, payload) => http.put(`/admin/merchant-applications/${id}`, payload),
  adminBanners: () => http.get('/admin/banners'),
  adminSaveBanner: (payload) => http.post('/admin/banners', payload),
  adminDeleteBanner: (id) => http.delete(`/admin/banners/${id}`),
  adminProducts: () => http.get('/admin/products'),
  adminProductViews: () => http.get('/admin/products/views'),
  adminSaveProduct: (payload) => http.post('/admin/products', payload),
  adminApproveProduct: (id, payload) => http.put(`/admin/products/${id}/approve`, payload),
  adminDeleteProduct: (id) => http.delete(`/admin/products/${id}`),
  adminReviews: () => http.get('/admin/reviews'),
  adminLogistics: () => http.get('/admin/logistics'),
  adminInventory: () => http.get('/admin/inventory'),

  uploadImage: (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return http.post('/api/upload/image', formData, {
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  },
  uploadFile: (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return http.post('/upload', formData, {
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  }
}
