import { Customer } from '@/data/customers/customer.model';
import { CommonResponseType, PageAble } from '@/helpers/types';
import { request } from '@/services/request';
import omit from 'lodash.omit';

export const customer_requests = {
    async getAll(params?: {
        cargoId?: string;
        aviaCargoId?: string;
        autoCargoId?: string;
        page?: number;
        sort?: string;
        direction?: string;
    }) {
        return request.get<CommonResponseType<PageAble<Customer>>>('/clients/list', { params });
    },

    async notAttached(params: { clientName?: string; partyId: number; page: number }) {
        return request.get<CommonResponseType<Customer[]>>('/clients/notAttached', { params });
    },

    async edit(body: {
        clientId: number;

        fullName: string;
        phone: string;
        address: string;
        pinfl: string;
        passportSeries: string;
        dateOfBirth: string;
    }) {
        const id = body.clientId;
        const data = omit(body, 'clientId');
        return request.put<CommonResponseType<Customer[]>>(`/clients/edit/${id}`, data);
    },
    async create(body: { fullName: string; phone: string; address: string; pinfl: string; passport: string; dateOfBirth: string }) {
        return request.post<CommonResponseType<Customer[]>>(`/clients/create`, body);
    },
    async delete(params: { clientId: number | string }) {
        return request.delete<CommonResponseType>(`/clients/delete/${params.clientId}`);
    },
    async downloadClientsExcel() {
        return request.get<Blob>('/clients/download', { responseType: 'blob' });
    },
};
