import { API } from '../api/API';

export const collaborationService = {
    getWorknotes: async (requestId: string, requestType: string) => {
        const response: any = await API.getWorknotes(requestId, requestType);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to fetch worknotes');
        return response.data?.data || response.data;
    },
    addWorknote: async (data: {
        requestId?: string;
        applicationId?: string;
        requestType: string;
        noteText: string;
        noteType?: string;
        attachments?: File[];
    }) => {
        // If attachments exist, we should use a different approach or multi-part
        // For now, handling simple text.
        const response: any = await API.addWorknote(data);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to add worknote');
        return response.data?.data || response.data;
    },
    addParticipant: async (data: any) => {
        const response: any = await API.addParticipant(data);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to add participant');
        return response.data;
    },
    removeParticipant: async (id: string) => {
        const response: any = await API.removeParticipant(id);
        if (!response.ok) throw new Error(response.data?.message || 'Failed to remove participant');
        return response.data;
    }
};
