import { useRequestHandler } from '@/UI-kit/composables';
import { ref } from 'vue';
import { IApiDocumentModule, IPendingSaveImage, IUserPhotoDoc } from '@/modules/documents';

export default function (api: IApiDocumentModule) {
    const pendingImageList = ref<IPendingSaveImage[]>([]);
    const deleteImageList = ref<IUserPhotoDoc[]>([]);

    const { requestHandler: saveImageDocument } = useRequestHandler({
        request: async ({ formData, documentId }) =>
            api.saveImageDocument({ formData, documentId }),
        catch: async (err) => Promise.reject(err),
    });

    const { requestHandler: removeImageHandler } = useRequestHandler({
        request: async ({ imageId }: { imageId: number }) => api.deleteImageDocument({ imageId }),
        catch: async (err) => Promise.reject(err),
    });

    return {
        pendingImageList,
        deleteImageList,
        saveImageDocument,
        removeImageHandler,
    };
}
