import {z} from 'zod' export type GetApiFacilitiesRegionRegionUuidSinceArgs = {regionUuid: string, since: number}; export type GetApiFacilitiesRegionRegionUuidSinceOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const communityReferenceDto = z.object({caption: z.string().optional(), externalId: z.string().optional(), uuid: z.string()}); export const districtReferenceDto = z.object({caption: z.string().optional(), externalId: z.string().optional(), uuid: z.string()}); export const regionReferenceDto = z.object({caption: z.string().optional(), externalId: z.string().optional(), uuid: z.string()}); export const facilityDto = z.object({additionalInformation: z.string().max(255).optional(), archived: z.boolean().optional(), areaType: z.enum(["URBAN", "RURAL", "UNKNOWN"]).optional(), centrallyManaged: z.boolean().optional(), changeDate: z.string().optional(), city: z.string().max(512).optional(), community: communityReferenceDto.optional(), contactPersonEmail: z.string().max(1000000).optional(), contactPersonFirstName: z.string().max(1000000).optional(), contactPersonLastName: z.string().max(1000000).optional(), contactPersonPhone: z.string().max(1000000).optional(), creationDate: z.string().optional(), district: districtReferenceDto.optional(), externalID: z.string().max(512).optional(), houseNumber: z.string().max(512).optional(), latitude: z.number().gte(-90).lte(90).optional(), longitude: z.number().gte(-180).lte(180).optional(), name: z.string().max(255).optional(), postalCode: z.string().max(512).optional(), publicOwnership: z.boolean().optional(), region: regionReferenceDto.optional(), street: z.string().max(4096).optional(), type: z.enum(["ASSOCIATION", "BUSINESS", "BAR", "CAMPSITE", "CANTINE", "CHILDRENS_DAY_CARE", "CHILDRENS_HOME", "CORRECTIONAL_FACILITY", "CRUISE_SHIP", "ELDERLY_DAY_CARE", "EVENT_VENUE", "FOOD_STALL", "HOLIDAY_CAMP", "HOMELESS_SHELTER", "HOSPITAL", "HOSTEL", "HOTEL", "KINDERGARTEN", "LABORATORY", "MASS_ACCOMMODATION", "MILITARY_BARRACKS", "MOBILE_NURSING_SERVICE", "NIGHT_CLUB", "OTHER_ACCOMMODATION", "OTHER_CARE_FACILITY", "OTHER_CATERING_OUTLET", "OTHER_EDUCATIONAL_FACILITY", "OTHER_LEISURE_FACILITY", "OTHER_MEDICAL_FACILITY", "OTHER_RESIDENCE", "OTHER_WORKING_PLACE", "OTHER_COMMERCE", "OUTPATIENT_TREATMENT_FACILITY", "PLACE_OF_WORSHIP", "PUBLIC_PLACE", "REFUGEE_ACCOMMODATION", "REHAB_FACILITY", "RESTAURANT", "RETIREMENT_HOME", "RETAIL", "WHOLESALE", "SCHOOL", "SWIMMING_POOL", "THEATER", "UNIVERSITY", "ZOO", "AMBULATORY_SURGERY_FACILITY", "DIALYSIS_FACILITY", "DAY_HOSPITAL", "MATERNITY_FACILITY", "MEDICAL_PRACTICE", "DENTAL_PRACTICE", "OTHER_MEDICAL_PRACTICE", "DIAGNOSTIC_PREVENTATIVE_THERAPEUTIC_FACILITY", "EMERGENCY_MEDICAL_SERVICES", "ELDERLY_CARE_FACILITY", "DISABLED_PERSON_HABITATION", "CARE_RECIPIENT_HABITATION", "VISITING_AMBULATORY_AID", "AFTER_SCHOOL"]).optional(), uuid: z.string().min(20).max(36).optional()}); export const getApiFacilitiesRegionRegionUuidSinceResponse = z.array(facilityDto); 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 }; /** * GET /facilities/region/{regionUuid}/{since} */ export const getApiFacilitiesRegionRegionUuidSince = async (args: GetApiFacilitiesRegionRegionUuidSinceArgs, options: GetApiFacilitiesRegionRegionUuidSinceOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json; charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/facilities/region/${encodeURIComponent(String(args.regionUuid))}/${encodeURIComponent(String(args.since))}${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(getApiFacilitiesRegionRegionUuidSinceResponse, await res.json()) };