import { CreateProductAttributeRequestType, DeleteProductAttributeRequestType, ListProductAttributeRequestType, ProductAttribute, ProductAttributeBatchUpdateRequestType, ProductAttributeBatchUpdateResponseType, ProductAttributeByIdRequestType, UpdateProductAttributeRequestType, } from './types'; import { AxiosInstance } from 'axios'; export default class ProductAttributes { private readonly client: AxiosInstance; constructor(client: AxiosInstance) { this.client = client; } async create(data: CreateProductAttributeRequestType) { const response = await this.client.post( 'products/attributes', data ); return response.data; } async getById({ id }: ProductAttributeByIdRequestType) { const response = await this.client.get( `products/attributes/${id}` ); return response.data; } async list( params?: ListProductAttributeRequestType ): Promise<{ data: ProductAttribute[]; count: number; totalPages: number; }> { const response = await this.client.get( 'products/attributes', { params } ); return { data: response.data, count: response.headers['x-wp-total'], totalPages: response.headers['x-wp-totalpages'], }; } async updateById({ id, data }: UpdateProductAttributeRequestType) { const response = await this.client.put( `products/attributes/${id}`, data ); return response.data; } async deleteById({ id, data }: DeleteProductAttributeRequestType) { const response = await this.client.delete( `products/attributes/${id}`, { data } ); return response.data; } async batch(data: ProductAttributeBatchUpdateRequestType) { const response = await this.client.post< ProductAttributeBatchUpdateResponseType >('products/attributes/batch', data); return response.data; } }