import {z} from 'zod' export type PatchInstallmentsRequest = {installmentLocators: Array, generateTime?: string | undefined, dueTime?: string | undefined, autopayTime?: string | undefined}; export type PatchApiBillingTenantLocatorInstallmentsArgs = {tenantLocator: string, body: PatchInstallmentsRequest}; export type PatchApiBillingTenantLocatorInstallmentsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const installmentItem = z.object({locator: z.string(), installmentLocator: z.string(), chargeLocator: z.string(), elementLocator: z.string(), elementStaticLocator: z.string(), chargeType: z.string(), chargeCategory: z.string(), amount: z.number(), invoiceItemLocator: z.string().optional(), createdAt: z.string(), createdBy: z.string(), reversalOfInstallmentItemLocator: z.string().optional()}); export const installment = z.object({locator: z.string(), installmentLatticeLocator: z.string(), accountLocator: z.string(), currency: z.string(), timezone: z.string(), installmentFrameIndex: z.number().int(), quoteLocator: z.string().optional(), policyLocator: z.string().optional(), transactionLocator: z.string().optional(), installmentStartTime: z.string(), installmentEndTime: z.string(), coverageStartTime: z.string(), coverageEndTime: z.string(), installmentDuration: z.number(), coverageDuration: z.number(), generateTime: z.string(), dueTime: z.string(), invoiceLocator: z.string().optional(), createdAt: z.string(), createdBy: z.string(), updatedAt: z.string(), updatedBy: z.string(), installmentItems: z.array(installmentItem), reversalOfInstallmentLocator: z.string().optional(), termLocator: z.string().optional(), migratedFromInstallmentLocator: z.string().optional(), autopayTime: z.string().optional(), enhancedByPlugin: z.boolean().optional()}); export const patchApiBillingTenantLocatorInstallmentsResponse = z.array(installment); 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 }; /** * PATCH /billing/{tenantLocator}/installments */ export const patchApiBillingTenantLocatorInstallments = async (args: PatchApiBillingTenantLocatorInstallmentsArgs, options: PatchApiBillingTenantLocatorInstallmentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/billing/${encodeURIComponent(String(args.tenantLocator))}/installments${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(patchApiBillingTenantLocatorInstallmentsResponse, await res.json()) };