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

export const appAlarmList = (params: AppAlarmListParams) => {
  return resultify(
    axios.post<AppAlarmListResponse>(API_URL_ALARM.appAlarmList(), params),
  );
};

export const useAppAlarmListMutation = (options?: UseMutationOptions<AppAlarmListResponse, NiceAxiosError, AppAlarmListParams>) => {
  const mutation = useMutation<AppAlarmListResponse, NiceAxiosError, AppAlarmListParams>({
    ...options,
    mutationFn: (params: AppAlarmListParams) => appAlarmList(params),
  });

  return {
    ...mutation,
  };
};
