import api, {HEADERS} from '@config/api';
import {getResponseQuery} from '@services/utils';

export const sendMessagesLogFile = async ({
  uri,
  cursor,
  capacity,
  fileName,
}: {
  uri: string;
  cursor: number;
  capacity: number;
  fileName: string;
}): Promise<void> => {
  const query = new URLSearchParams({
    cursor: cursor.toString(),
    capacity: capacity.toString(),
  });

  const formData = new FormData();

  formData.append('log', {
    uri: uri,
    name: fileName,
    type: 'text/plain',
  } as unknown as Blob);

  const response = await api.post(
    `/horus/chats/log-report?${query}`,
    formData,
    {
      headers: {[HEADERS.CONTENT_TYPE]: 'multipart/form-data'},
      withErrorBanner: false,
    },
  );
  return getResponseQuery(response);
};
