import client from '@/api/client';

const API_BASE = '/collaboration';

export const worknoteService = {
    getWorknotes: async (requestId: string, requestType: string) => {
        const response = await client.get(`${API_BASE}/worknotes`, { requestId, requestType });
        return response.data;
    },

    addWorknote: async (data: {
        requestId: string;
        requestType: string;
        noteText: string;
        noteType?: string;
        tags?: string[];
        attachmentDocIds?: string[];
    }) => {
        const response = await client.post(`${API_BASE}/worknotes`, data);
        return response.data;
    },

    uploadAttachment: async (file: File, requestId?: string, requestType?: string) => {
        const formData = new FormData();
        formData.append('file', file);
        if (requestId) formData.append('requestId', requestId);
        if (requestType) formData.append('requestType', requestType);

        const response = await client.post(`${API_BASE}/upload`, formData, {
            headers: { 'Content-Type': 'multipart/form-data' }
        });
        return response.data;
    },

    revokeParticipant: async (participantId: string, reason?: string) => {
        const response = await client.delete(`${API_BASE}/participants/${participantId}`, { data: { reason } });
        return response.data;
    }
};

export default worknoteService;
