import { CreateShippingZoneRequestType, DeleteShippingZoneRequestType, ShippingZone, ShippingZoneByIdRequestType, UpdateShippingZoneRequestType, } from './types'; import { AxiosInstance } from 'axios'; export default class ShippingZones { private readonly client: AxiosInstance; constructor(client: AxiosInstance) { this.client = client; } async create(data: CreateShippingZoneRequestType): Promise { const response = await this.client.post( '/shipping/zones', data ); return response.data; } async getById({ id }: ShippingZoneByIdRequestType): Promise { const response = await this.client.get( `/shipping/zones/${id}` ); return response.data; } async list(): Promise<{ data: ShippingZone[]; count: number; totalPages: number; }> { const response = await this.client.get('/shipping/zones'); return { data: response.data, count: response.headers['x-wp-total'], totalPages: response.headers['x-wp-totalpages'], }; } async updateById({ id, data, }: UpdateShippingZoneRequestType): Promise { const response = await this.client.put( `/shipping/zones/${id}`, data ); return response.data; } async deleteById({ id, data: { force = true }, }: DeleteShippingZoneRequestType): Promise { const response = await this.client.delete( `/shipping/zones/${id}`, { data: { force, }, } ); return response.data; } }