import {z} from 'zod' export type CreateApiThermostatsCreateClimatePresetArgs = {body: {climate_preset_key: string, climate_preset_mode?: ('home' | 'away' | 'wake' | 'sleep' | 'occupied' | 'unoccupied') | undefined, cooling_set_point_celsius?: number | undefined, cooling_set_point_fahrenheit?: number | undefined, device_id: string, ecobee_metadata?: ({climate_ref?: string | undefined, is_optimized?: boolean | undefined, owner?: ('user' | 'system') | undefined}) | undefined, fan_mode_setting?: ('auto' | 'on' | 'circulate') | undefined, heating_set_point_celsius?: number | undefined, heating_set_point_fahrenheit?: number | undefined, hvac_mode_setting?: ('off' | 'heat' | 'cool' | 'heat_cool' | 'eco') | undefined, manual_override_allowed?: boolean | undefined, name?: (string | null) | undefined}}; export type CreateApiThermostatsCreateClimatePresetOptions = {baseUrl?: string | undefined, clientSession?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiThermostatsCreateClimatePresetResponse = z.object({}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a Climate Preset * * POST /thermostats/create_climate_preset * * Also accepts auth: pat_with_workspace, console_session_with_workspace, client_session_with_customer, api_key */ export const createApiThermostatsCreateClimatePreset = async (args: CreateApiThermostatsCreateClimatePresetArgs, options?: CreateApiThermostatsCreateClimatePresetOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, clientSession} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (clientSession !== undefined) headers.set('authorization', `Bearer ${clientSession}`) const url = `${baseUrl.replace(/\/+$/, '')}/thermostats/create_climate_preset${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiThermostatsCreateClimatePresetResponse, await res.json()) };