import {z} from 'zod' export type CreateApiThermostatsSchedulesListArgs = {body: {device_id: string, user_identifier_key?: string | undefined}}; export type CreateApiThermostatsSchedulesListOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const thermostatSchedule = z.object({climate_preset_key: z.string(), created_at: z.string(), device_id: z.string(), ends_at: z.string(), errors: z.array(z.object({error_code: z.string(), message: z.string()})), is_override_allowed: z.boolean().optional(), max_override_period_minutes: z.number().int().gt(0).nullable().optional(), name: z.string().nullable(), starts_at: z.string(), thermostat_schedule_id: z.string(), workspace_id: z.string()}); export const createApiThermostatsSchedulesListResponse = z.object({thermostat_schedules: z.array(thermostatSchedule)}); 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 }; /** * List Thermostat Schedules * * POST /thermostats/schedules/list * * Also accepts auth: client_session, pat_with_workspace, console_session_with_workspace, client_session_with_customer */ export const createApiThermostatsSchedulesList = async (args: CreateApiThermostatsSchedulesListArgs, options?: CreateApiThermostatsSchedulesListOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/thermostats/schedules/list${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(createApiThermostatsSchedulesListResponse, await res.json()) };