export function useOrdersService() {
  const { apiFetch } = useApi()

  return {
    getMyOrders(orderBy: string, perPage: number, status: string[], page: number) {
      const statusQuery = status
        .filter((s) => s !== undefined && s !== '')
        .map((s) => `status[]=${s}`)
        .join('&')

      return apiFetch(`/my-orders?order_by=${orderBy}&per_page=${perPage}&${statusQuery}&page=${page}`)
    },

    getById(id: number) {
      return apiFetch(`/my-orders/${id}`)
    },

    getReasons() {
      return apiFetch('/shipment-return-reasons')
    },

    returnShipment(data: Record<string, unknown>) {
      return apiFetch('/shipment-returns', { method: 'POST', body: data })
    },

    getRating(id: number) {
      return apiFetch(`/orders/${id}/rating`)
    },

    rateOrder(data: Record<string, unknown>) {
      return apiFetch('/rating/store', { method: 'POST', body: data })
    },
  }
}
