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 { 
  AppAlarmFindParams,
  AppAlarmFindResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const appAlarmFind = (params: AppAlarmFindParams) => {
  return resultify(
    axios.post<AppAlarmFindResponse>(API_URL_ALARM.appAlarmFind(), params),
  );
};

export const useAppAlarmFindMutation = (options?: UseMutationOptions<AppAlarmFindResponse, NiceAxiosError, AppAlarmFindParams>) => {
  const mutation = useMutation<AppAlarmFindResponse, NiceAxiosError, AppAlarmFindParams>({
    ...options,
    mutationFn: (params: AppAlarmFindParams) => appAlarmFind(params),
  });

  return {
    ...mutation,
  };
};
