import { queryAlarms } from '@/services/controller/DeviceController';
import { useCallback, useState } from 'react';

export default function useAlarmModel() {
  const [alarmData, setAlarmData] = useState<API.AlarmResponse | null>(null);
  const [loading, setLoading] = useState(false);
  const getAlarmData = useCallback(async () => {
    setLoading(true);
    try {
      const res = await queryAlarms(); // đổi URL cho phù hợp
      console.log('Alarm Data fetched:', res);

      setAlarmData(res || []);
    } catch (err) {
      console.error('Fetch alarm data failed', err);
    } finally {
      setLoading(false);
    }
  }, []);
  return {
    alarmData,
    loading,
    getAlarmData,
  };
}
