import {z} from 'zod' export type ObjectReference = {id?: number | undefined, name?: (string | null) | undefined}; export type AddressData = {axAddressId?: (number | null) | undefined, name?: (string | null) | undefined, completeAddress?: (string | null) | undefined, street?: (string | null) | undefined, zipCode?: (string | null) | undefined, city?: (string | null) | undefined, county?: (string | null) | undefined, state?: (string | null) | undefined, countryCode?: (string | null) | undefined}; export type InvoiceProfile = {id?: number | undefined, organization?: ObjectReference | undefined, name?: (string | null) | undefined, invoiceReference?: (string | null) | undefined, customerReference?: (string | null) | undefined, requisitionNumber?: (string | null) | undefined, invoiceAddressId?: (string | null) | undefined, deliveryAddressId?: (string | null) | undefined, deliveryAddress?: AddressData | undefined, invoiceAddress?: AddressData | undefined, consumerId?: (number | null) | undefined, contactPersonId?: (number | null) | undefined}; export type UpdateApiApiV1InvoiceProfilesIdArgs = {id: number, body: InvoiceProfile}; export type UpdateApiApiV1InvoiceProfilesIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const objectReference = z.object({id: z.number().int().optional(), name: z.string().nullable().optional()}); export const addressData = z.object({axAddressId: z.number().int().nullable().optional(), name: z.string().nullable().optional(), completeAddress: z.string().nullable().optional(), street: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), city: z.string().nullable().optional(), county: z.string().nullable().optional(), state: z.string().nullable().optional(), countryCode: z.string().nullable().optional()}); export const invoiceProfile = z.object({id: z.number().int().optional(), organization: objectReference.optional(), name: z.string().nullable().optional(), invoiceReference: z.string().nullable().optional(), customerReference: z.string().nullable().optional(), requisitionNumber: z.string().nullable().optional(), invoiceAddressId: z.string().nullable().optional(), deliveryAddressId: z.string().nullable().optional(), deliveryAddress: addressData.optional(), invoiceAddress: addressData.optional(), consumerId: z.number().int().nullable().optional(), contactPersonId: z.number().int().nullable().optional()}); 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 }; /** * PUT /api/v1/InvoiceProfiles/{id} */ export const updateApiApiV1InvoiceProfilesId = async (args: UpdateApiApiV1InvoiceProfilesIdArgs, options: UpdateApiApiV1InvoiceProfilesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/InvoiceProfiles/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(invoiceProfile, await res.json()) };