import { useMutation, useQueryClient, } from '@tanstack/react-query';
import { NullSeamClientError, useSeamClient } from '../../../../lib/index.js';
export function useUpdateClimateSettingSchedule() {
    const { client } = useSeamClient();
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: async (mutationPararms) => {
            if (client === null)
                throw new NullSeamClientError();
            return await client.thermostats.climateSettingSchedules.update(mutationPararms);
        },
        onSuccess: (updated) => {
            queryClient.setQueryData([
                'thermostats',
                'climate_setting_schedules',
                'get',
                {
                    climate_setting_schedule_id: updated.climate_setting_schedule_id,
                },
            ], (climateSettingSchedule) => {
                if (climateSettingSchedule == null) {
                    return;
                }
                return {
                    ...climateSettingSchedule,
                    ...updated,
                };
            });
            queryClient.setQueryData([
                'thermostats',
                'climate_setting_schedules',
                'list',
                { device_id: updated.device_id },
            ], (climateSettingSchedules) => {
                if (climateSettingSchedules == null) {
                    return [];
                }
                return climateSettingSchedules.map((climateSettingSchedule) => {
                    if (climateSettingSchedule.device_id === updated.device_id) {
                        return {
                            ...climateSettingSchedule,
                            ...updated,
                        };
                    }
                    return climateSettingSchedule;
                });
            });
        },
    });
}
//# sourceMappingURL=use-update-climate-setting-schedule.js.map