import {z} from 'zod' export type PwsGetGroupInterestHistory = {api_call_unique_identifier: string, client_id: number, group_id: number, interest_rate_id: number, user_id?: string | undefined, remarks?: string | undefined}; export type CreateApiPwsPwsCrInterestHistoryGroupGetArgs = {body: PwsGetGroupInterestHistory}; export type CreateApiPwsPwsCrInterestHistoryGroupGetOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getGroupInterestHistoryResponseHeader = z.object({error_id: z.number().int().optional(), error_desc: z.string().optional()}); export const getGroupInterestHistoryResponseBody = z.object({api_call_unique_identifier: z.string().min(1).max(40), client_id: z.number().int().gte(1), effective_date: z.string().min(1), interest_rate_descr: z.string().min(1), interest_rate_fixed: z.number().gte(0), interest_rate_fixed_grace: z.number().gte(0), interest_rate_id: z.number().int().gte(1), interest_rate_logic: z.string().min(1), interest_rate_logic_grace: z.string().min(1), interest_rate_perc: z.number().gte(0), interest_rate_perc_grace: z.number().gte(0), user_id: z.string().max(50).optional(), remarks: z.string().max(200).optional(), is_default: z.boolean().optional(), interest_rate_perc_elevated: z.number().gte(0).optional(), interest_rate_fixed_elevated: z.number().gte(0).optional(), interest_rate_logic_elevated: z.string().optional(), interest_rate_min_perc: z.number().gte(0).optional(), interest_rate_min_fixed: z.number().gte(0).optional(), interest_rate_min_logic: z.string().optional(), interest_rate_max_perc: z.number().gte(0).optional(), interest_rate_max_fixed: z.number().gte(0).optional(), interest_rate_max_logic: z.string().optional(), group_id: z.number().int().optional(), seq_no: z.number().int().optional(), change_event: z.string().optional(), changed_dt: z.string().optional()}); export const getGroupInterestHistoryResponse = z.object({header: getGroupInterestHistoryResponseHeader.optional(), body: getGroupInterestHistoryResponseBody.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 }; /** * Get Group Interest History * * POST /pws/pws_cr_interest_history_group_get/ */ export const createApiPwsPwsCrInterestHistoryGroupGet = async (args: CreateApiPwsPwsCrInterestHistoryGroupGetArgs, options?: CreateApiPwsPwsCrInterestHistoryGroupGetOptions) => { const {baseUrl = "https://api.uat.paymentology.com/ppws/api", 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(/\/+$/, '')}/pws/pws_cr_interest_history_group_get/${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(getGroupInterestHistoryResponse, await res.json()) };