import { useMutation, useQueryClient, } from '@tanstack/react-query';
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
export function useSetThermostatOff() {
    const { client } = useSeamClient();
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: async (mutationParams) => {
            if (client === null)
                throw new NullSeamClientError();
            return await client.thermostats.off(mutationParams);
        },
        onSuccess: (_data, variables) => {
            queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (thermostat) => {
                if (thermostat == null) {
                    return;
                }
                return getUpdatedThermostat(thermostat);
            });
            queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (thermostats) => {
                if (thermostats == null) {
                    return [];
                }
                return thermostats.map((thermostat) => {
                    if (thermostat.device_id === variables.device_id) {
                        return getUpdatedThermostat(thermostat);
                    }
                    return thermostat;
                });
            });
        },
    });
}
function getUpdatedThermostat(thermostat) {
    return {
        ...thermostat,
        properties: {
            ...thermostat.properties,
            is_fan_running: false,
            current_climate_setting: {
                ...thermostat.properties.current_climate_setting,
                automatic_cooling_enabled: false,
                automatic_heating_enabled: false,
                hvac_mode_setting: 'off',
            },
        },
    };
}
//# sourceMappingURL=use-set-thermostat-off.js.map