import { useMutation, useQueryClient, } from '@tanstack/react-query';
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
export function useDeleteThermostatClimatePreset() {
    const { client } = useSeamClient();
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: async (variables) => {
            if (client === null)
                throw new NullSeamClientError();
            await client.thermostats.deleteClimatePreset(variables);
        },
        onSuccess: (_data, variables) => {
            queryClient.setQueryData(['devices', 'get', { device_id: variables.device_id }], (device) => {
                if (device == null) {
                    return;
                }
                return getUpdatedDevice(device, variables);
            });
            queryClient.setQueryData(['devices', 'list', { device_id: variables.device_id }], (devices) => {
                if (devices == null) {
                    return [];
                }
                return devices.map((device) => {
                    if (device.device_id === variables.device_id) {
                        return getUpdatedDevice(device, variables);
                    }
                    return device;
                });
            });
        },
    });
}
function getUpdatedDevice(device, variables) {
    return {
        ...device,
        properties: {
            ...device.properties,
            available_climate_presets: device.properties.available_climate_presets.filter((preset) => {
                return preset.climate_preset_key !== variables.climate_preset_key;
            }),
        },
    };
}
//# sourceMappingURL=use-delete-thermostat-climate-preset.js.map