import {z} from 'zod' export type GetApiV2PropertyClaimsPropertyClaimIdMaterialReadingsArgs = {'X-Encircle-Attribution'?: string | undefined, 'X-Encircle-Request'?: string | undefined, room_id?: number | undefined, order?: ('newest' | 'oldest') | undefined, limit?: number | undefined, after?: unknown | undefined}; export type GetApiV2PropertyClaimsPropertyClaimIdMaterialReadingsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const materialReadingResponse = z.object({material_type: z.enum(["drywall", "carpet", "concrete", "woodsillplate", "ceramictile", "hardwood", "laminate", "plywood", "vinyl", "plaster", "paneling", "subfloor", "framing", "particleboard", "custom", "gypcrete", "osb"]), name: z.string().nullable(), moisture_point_number: z.number().int(), moisture_point_id: z.number().int(), structure_id: z.number().int(), room_id: z.number().int(), meter: z.string().nullable(), moisture_content: z.number(), temperature: z.number().nullable(), dry_standard: z.number().nullable(), created: z.string(), creator: z.object({actor_type: z.literal("User"), actor_identifier: z.string()}), time: z.string()}); export const getApiV2PropertyClaimsPropertyClaimIdMaterialReadingsResponse = z.object({list: z.array(materialReadingResponse), cursor: z.object({order: z.string(), limit: z.number().int(), after: z.string().nullable()})}); 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 }; /** * Find Material Readings * * GET /v2/property_claims/{property_claim_id}/material_readings */ export const getApiV2PropertyClaimsPropertyClaimIdMaterialReadings = async (args: GetApiV2PropertyClaimsPropertyClaimIdMaterialReadingsArgs, options: GetApiV2PropertyClaimsPropertyClaimIdMaterialReadingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Encircle-Attribution'] != null) headers.set("X-Encircle-Attribution", String(args['X-Encircle-Attribution'])) if (args['X-Encircle-Request'] != null) headers.set("X-Encircle-Request", String(args['X-Encircle-Request'])) if (args.room_id != null) query.append("room_id", String(args.room_id)) if (args.order != null) query.append("order", String(args.order)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.after != null) query.append("after", String(args.after)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/property_claims/${encodeURIComponent(String(args.property_claim_id))}/material_readings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2PropertyClaimsPropertyClaimIdMaterialReadingsResponse, await res.json()) };