import {z} from 'zod' export type DateInPast = string; export type MonetaryCents = number; export type Date = string; export type PropertyInspectionPatchRequest = {insurer_identifier?: string | undefined, policyholder_name?: (string | null) | undefined, full_address?: (string | null) | undefined, policyholder_email_address?: (string | null) | undefined, policyholder_phone_number?: (string | null) | undefined, inspection_date?: DateInPast | undefined, underwriter?: (string | null) | undefined, inspection_creator?: (string | null) | undefined, estimated_building_value?: MonetaryCents | undefined, insurance_company_name?: (string | null) | undefined, insurance_broker_name?: (string | null) | undefined, policy_number?: (string | null) | undefined, policy_renewal_date?: Date | undefined}; export type PatchApiV1PropertyInspectionsPropertyInspectionIdArgs = {'X-Encircle-Attribution'?: string | undefined, 'X-Encircle-Request'?: string | undefined, body: PropertyInspectionPatchRequest}; export type PatchApiV1PropertyInspectionsPropertyInspectionIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const uUID = z.string(); export const dateInPast = z.string(); export const monetaryCents = z.number().int(); export const date = z.string(); export const propertyInspectionResponse = z.object({organization_id: uUID, brand_id: z.number().int().nullable(), id: z.number().int(), permalink_url: z.string(), insurer_identifier: z.string(), policyholder_name: z.string().nullable(), full_address: z.string().nullable(), policyholder_email_address: z.string().nullable(), policyholder_phone_number: z.string().nullable(), inspection_date: dateInPast, underwriter: z.string().nullable(), inspection_creator: z.string().nullable(), estimated_building_value: monetaryCents, insurance_company_name: z.string().nullable(), insurance_broker_name: z.string().nullable(), policy_number: z.string().nullable(), policy_renewal_date: date}); 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 }; /** * Update a property inspection * * PATCH /v1/property_inspections/{property_inspection_id} */ export const patchApiV1PropertyInspectionsPropertyInspectionId = async (args: PatchApiV1PropertyInspectionsPropertyInspectionIdArgs, options: PatchApiV1PropertyInspectionsPropertyInspectionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/property_inspections/${encodeURIComponent(String(args.property_inspection_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(propertyInspectionResponse, await res.json()) };