import { BoxStatus } from '@/data/box/box.model';
import { Product, CreateProductBodyType, UpdateProductBodyType } from '@/data/item/item.mode';
import { CommonResponseType, PageAble } from '@/helpers/types';
import { request } from '@/services/request';

export const item_requests = {
    async getAll(params?: {
        packetId?: number | string;
        partyId?: number | string;
        name?: string;
        trekId?: string;
        page?: number;
        sort?: string;
        status?: BoxStatus;
        direction?: 'asc' | 'desc';
    }) {
        return request.get<CommonResponseType<PageAble<Product>>>('/items/list', { params });
    },
    async create({ packetId, ...body }: CreateProductBodyType) {
        return request.post<CommonResponseType>('/items/create', body, {
            params: { packetId },
        });
    },
    async update({ itemId, ...body }: UpdateProductBodyType) {
        return request.put<CommonResponseType<Product[]>>('/items/update', body, {
            params: { itemId },
        });
    },
    async find(params: { itemId?: number | string }) {
        return request.get<CommonResponseType<Product[]>>('/items/find', { params });
    },
    async delete(params: { itemId: number | string }) {
        return request.delete<CommonResponseType>('/items/delete', { params });
    },
    async addPhotos(params: { itemId: number | string; weight: number; summa: number }, body: FormData) {
        return request.post<CommonResponseType>('/photos/assignPhoto', body, {
            params,
            headers: {
                'Content-Type': 'multipart/form-data',
            },
        });
    },
};
