import { api } from '../api';

export type CreateOrderPayload = {
  items: { product_id: number; qty: number }[];
  billing?: Record<string, any>;
  shipping?: Record<string, any>;
  status?: string;
  payment_method?: string;
};

export const OrdersApi = {
  list: (params?: Record<string, any>) => api.get('/orders', params),
  get: (id: number) => api.get(`/orders/${id}`),
  create: (payload: CreateOrderPayload) => api.post('/orders', payload),
  update: (id: number, payload: any) => api.wpFetch(`/orders/${id}`, {
      method: 'PATCH',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(payload),
  }),
  payments: async () => api.get('/payments'),
  shippings: async () => api.get('/shippings'),
  countries: () => api.get('/countries'),
};
