import api from 'src/config/api';
import {
  type FormAttributes,
  type FormPaginationResponse,
} from 'src/types/forms';
import { type Pagination } from 'src/types/services';
import {
  type SurveyListParams,
  type SurveysNotificationsResponse,
} from 'src/types/surveys';

export type AvailableSurveysPaginationResponse = Pagination<FormAttributes[]>;

export const getSurveysNotifications = () =>
  api.get<SurveysNotificationsResponse>('red-bubbles/surveys');

export const getAvailableSurveys = (params: SurveyListParams) =>
  api.get<AvailableSurveysPaginationResponse>(`/forms`, {
    params: {
      ...params,
      type: 'SURVEY',
      status: 'ENABLED',
    },
  });

export const getCompletedSurveys = (userId: number, params: SurveyListParams) =>
  api.get<FormPaginationResponse>(`/users/${userId}/forms`, {
    params: {
      ...params,
      type: 'SURVEY',
    },
  });

export const downloadSurveyResponse = (templateId: number, formId: number) =>
  api.get(`/forms/${templateId}/answers/${formId}/report`, {
    responseType: 'blob',
  });
