import request from './request'
import type {
  Good,
  GoodDetail,
  CreateGoodRequest,
  UpdateGoodRequest,
  BatchCreateGoodsRequest,
  BatchPriorityRequest,
  GoodsFilter,
  PaginatedResult,
  CreateCustomGoodRequest,
  UpdateCustomGoodContentRequest,
} from '@/types'

export const goodsApi = {
  // Get goods list
  getGoodsList: (params: GoodsFilter) => {
    return request.get<any, PaginatedResult<Good>>('/goods', { params })
  },

  // Get good by id
  getGoodById: (id: string) => {
    return request.get<any, GoodDetail>(`/goods/${id}`)
  },

  // Create good
  createGood: (data: CreateGoodRequest) => {
    return request.post<any, Good>('/goods', data)
  },

  createCustomGood: (data: CreateCustomGoodRequest) => {
    return request.post<any, GoodDetail>('/goods/custom', data)
  },

  updateCustomGoodContent: (id: string, data: UpdateCustomGoodContentRequest) => {
    return request.patch<any, GoodDetail>(`/goods/${id}/custom-content`, data)
  },

  // Update good
  updateGood: (id: string, data: UpdateGoodRequest) => {
    return request.patch<any, Good>(`/goods/${id}`, data)
  },

  // Delete good
  deleteGood: (id: string) => {
    return request.delete(`/goods/${id}`)
  },

  // Batch create goods
  batchCreateGoods: (data: BatchCreateGoodsRequest) => {
    return request.post<any, Good[]>('/goods/batch', data)
  },

  // Batch update priority
  batchUpdatePriority: (data: BatchPriorityRequest) => {
    return request.patch<any, { count: number }>('/goods/batch-priority', data)
  },
}
