import { CreateProductRequestType, DeleteProductRequestType, ListProductRequestType, Product, ProductBatchUpdateRequestType, ProductBatchUpdateResponseType, ProductByIdRequestType, UpdateProductRequestType, } from './types'; import { AxiosInstance } from 'axios'; export default class Products { private readonly client: AxiosInstance; constructor(client: AxiosInstance) { this.client = client; } async create(data: CreateProductRequestType) { const response = await this.client.post('products', data); return response.data; } async getById({ id }: ProductByIdRequestType) { const response = await this.client.get(`products/${id}`); return response.data; } async list( params?: ListProductRequestType ): Promise<{ data: Product[]; count: number; totalPages: number; }> { const response = await this.client.get('products', { params }); return { data: response.data, count: response.headers['x-wp-total'], totalPages: response.headers['x-wp-totalpages'], }; } async updateById({ id, data }: UpdateProductRequestType) { const response = await this.client.put(`products/${id}`, data); return response.data; } async deleteById({ id, data: { force = false } }: DeleteProductRequestType) { const response = await this.client.delete(`products/${id}`, { data: { force, }, }); return response.data; } async batch(data: ProductBatchUpdateRequestType) { const response = await this.client.post( 'products/batch', data ); return response.data; } }