import { RemainingAttemptsSocket } from 'src/types/forms';
import { DeleteSurveySocket, DisabledSurveySocket } from 'src/types/surveys';

import {
  updateAvailableSurveyRemainingAttemps,
  dropAvailableSurvey,
  invalidateAvailableSurveyList,
  invalidateSurveysNotifications,
} from 'src/components/dashboard/surveys/queries';

export const updateRemainingAttemps = (data: RemainingAttemptsSocket) => {
  const { id, remainingAttempts } = data;

  updateAvailableSurveyRemainingAttemps(id, remainingAttempts);
};

export const deleteSurvey = (data: DeleteSurveySocket) => {
  dropAvailableSurvey(data?.formId);
  invalidateSurveysNotifications();
};

export const disabledSurvey = (data: DisabledSurveySocket) => {
  dropAvailableSurvey(data?.id);
  invalidateSurveysNotifications();
};

export const enabledSurvey = () => {
  invalidateAvailableSurveyList();
  invalidateSurveysNotifications();
};
