import {z} from 'zod' export type ServiceChannelServicesMessagingAssetsAddAssetMeterReadingRequestItem = {AssetId: number, AssetMeterId?: number | undefined, AssetTypeMeterId?: number | undefined, Value: number, Notes: string, TrackingNumber?: number | undefined, UpdatedDate: string}; export type CreateApiAssetsCreateAssetMeterReadingsBulkArgs = {body: Array}; export type CreateApiAssetsCreateAssetMeterReadingsBulkOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelServicesMessagingAssetsAssetMeterReadingResponseItem = z.object({Id: z.number().int().optional(), AssetMeterId: z.number().int().optional(), AssetTypeMeterId: z.number().int().optional(), AssetTypeMeterName: z.string().optional(), UnitOfMeasureId: z.number().int().optional(), UnitOfMeasureName: z.string().optional(), Value: z.number().optional(), TrackingNumber: z.number().int().optional(), Notes: z.string().optional(), UpdatedBy: z.number().int().optional(), UpdatedByUserName: z.string().optional(), UpdatedDate: z.string().optional()}); export const createApiAssetsCreateAssetMeterReadingsBulkResponse = z.array(serviceChannelServicesMessagingAssetsAssetMeterReadingResponseItem); 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 }; /** * Asset meter readings bulk create * * POST /assets/CreateAssetMeterReadingsBulk */ export const createApiAssetsCreateAssetMeterReadingsBulk = async (args: CreateApiAssetsCreateAssetMeterReadingsBulkArgs, options?: CreateApiAssetsCreateAssetMeterReadingsBulkOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/assets/CreateAssetMeterReadingsBulk${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(createApiAssetsCreateAssetMeterReadingsBulkResponse, await res.json()) };