import axios from 'axios';
import { API_URL_ALARM } from '@/shared/api/api-url-alarm';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  AppAlarmConsentParams,
  AppAlarmConsentResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const appAlarmConsent = (params: AppAlarmConsentParams) => {
  return resultify(
    axios.post<AppAlarmConsentResponse>(API_URL_ALARM.appAlarmConsent(), params),
  );
};

export const useAppAlarmConsentMutation = (options?: UseMutationOptions<AppAlarmConsentResponse, NiceAxiosError, AppAlarmConsentParams>) => {
  const mutation = useMutation<AppAlarmConsentResponse, NiceAxiosError, AppAlarmConsentParams>({
    ...options,
    mutationFn: (params: AppAlarmConsentParams) => appAlarmConsent(params),
  });

  return {
    ...mutation,
  };
};
