import {z} from 'zod' export type CreateApiPosfinancingRestV2LoansIdSavingsScheduleArgs = {id: string, body: {calculatorNames?: (Array<'SOLO' | 'ENERFLO' | 'SUBCONTRACTOR_HUB' | 'SOLARGRAF' | 'ARCADIA_SWITCH' | 'VISION' | 'ARTEMIS' | 'ENERGY_PAL' | 'PURE_ENERGY' | 'SUNTRIA' | 'PATTER_AI' | 'PIPE' | 'LIGHT_FUSION' | 'AURORA'>) | undefined, firstYearSchedule: Array<{month: number, utilityWithoutSolar: {consumption: {unit?: 'kWh' | undefined, value: number} | null, payment: {type: 'USD' | 'CAD', value: number}}, utilityWithSolar: {solarConsumption: {unit?: 'kWh' | undefined, value: number} | null, utilityPayment: {type: 'USD' | 'CAD', value: number}, solarPayment: {type: 'USD' | 'CAD', value: number}, utilityConsumption: {unit?: 'kWh' | undefined, value?: number | undefined} | null}, savings: {type: 'USD' | 'CAD', value: number}}>, fullTermSchedule: Array<{year: number, utilityWithoutSolar: {consumption: {unit?: 'kWh' | undefined, value: number} | null, payment: {type: 'USD' | 'CAD', value: number}}, utilityWithSolar: {solarConsumption: {unit?: 'kWh' | undefined, value: number} | null, utilityPayment: {type: 'USD' | 'CAD', value: number}, solarPayment: {type: 'USD' | 'CAD', value: number}, utilityConsumption: {unit?: 'kWh' | undefined, value?: number | undefined} | null, solarRate: {unit: 'DOLLAR_PER_kWh', price?: number | undefined}}, savings: {type: 'USD' | 'CAD', value: number}}>} | null}; export type CreateApiPosfinancingRestV2LoansIdSavingsScheduleOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const schemaObject13 = z.object({id: z.string().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 }; /** * Create a Production and Savings Schedule * * POST /posfinancing/rest/v2/loans/{id}/savings-schedule */ export const createApiPosfinancingRestV2LoansIdSavingsSchedule = async (args: CreateApiPosfinancingRestV2LoansIdSavingsScheduleArgs, options?: CreateApiPosfinancingRestV2LoansIdSavingsScheduleOptions) => { const {baseUrl = "https://devint01-api.goodleap.com", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/posfinancing/rest/v2/loans/${encodeURIComponent(String(args.id))}/savings-schedule${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(schemaObject13, await res.json()) };