import {z} from 'zod' export type IntectBalancePeriod = {Id?: number | undefined, BalanceId?: number | undefined, EarningStartDate?: string | undefined, EarningEndDate?: string | undefined, SpendingStartDate?: string | undefined, SpendingEndDate?: string | undefined, SpecialIdentifier?: string | undefined, BalanceDefinition?: IntectBalanceDefinition | undefined, Name?: string | undefined}; export type IntectBalanceDefinition = {Id?: number | undefined, CompanyId?: (number | null) | undefined, CountryId?: (number | null) | undefined, Name?: string | undefined, SpecialIdentifier?: string | undefined, IsConfigurable?: boolean | undefined, AmountEnabled?: boolean | undefined, TaxEnabled?: boolean | undefined, SecondaryAmountEnabled?: boolean | undefined, TertiaryAmountEnabled?: boolean | undefined, DaysEnabled?: boolean | undefined, SecondaryDaysEnabled?: boolean | undefined, HoursEnabled?: boolean | undefined, BaseAmountEnabled?: boolean | undefined, HasPeriods?: boolean | undefined, SuspendedDaysEnabled?: boolean | undefined, IsActive?: boolean | undefined, BaseCalculationMethodId?: (number | null) | undefined, BalanceEarningIntervalId?: (number | null) | undefined, UnitsEarnedPerInterval?: (number | null) | undefined, EarningFixedAmount?: (number | null) | undefined, EarningPercentage?: (number | null) | undefined, TerminationMethodId?: (number | null) | undefined, SpendingMethodId?: (number | null) | undefined, BalancePeriods?: Array | undefined}; export type UpdateApiApiBalancesDefinitionsUpdateArgs = {body: IntectBalanceDefinition}; export type UpdateApiApiBalancesDefinitionsUpdateOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectBalancePeriod = z.object({Id: z.number().int().optional(), BalanceId: z.number().int().optional(), EarningStartDate: z.string().optional(), EarningEndDate: z.string().optional(), SpendingStartDate: z.string().optional(), SpendingEndDate: z.string().optional(), SpecialIdentifier: z.string().optional(), BalanceDefinition: z.lazy(() => intectBalanceDefinition.optional()), Name: z.string().optional()}); export const intectBalanceDefinition: z.ZodType = z.object({Id: z.number().int().optional(), CompanyId: z.number().int().nullable().optional(), CountryId: z.number().int().nullable().optional(), Name: z.string().optional(), SpecialIdentifier: z.string().optional(), IsConfigurable: z.boolean().optional(), AmountEnabled: z.boolean().optional(), TaxEnabled: z.boolean().optional(), SecondaryAmountEnabled: z.boolean().optional(), TertiaryAmountEnabled: z.boolean().optional(), DaysEnabled: z.boolean().optional(), SecondaryDaysEnabled: z.boolean().optional(), HoursEnabled: z.boolean().optional(), BaseAmountEnabled: z.boolean().optional(), HasPeriods: z.boolean().optional(), SuspendedDaysEnabled: z.boolean().optional(), IsActive: z.boolean().optional(), BaseCalculationMethodId: z.number().int().nullable().optional(), BalanceEarningIntervalId: z.number().int().nullable().optional(), UnitsEarnedPerInterval: z.number().nullable().optional(), EarningFixedAmount: z.number().nullable().optional(), EarningPercentage: z.number().nullable().optional(), TerminationMethodId: z.number().int().nullable().optional(), SpendingMethodId: z.number().int().nullable().optional(), BalancePeriods: z.array(intectBalancePeriod).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 }; /** * Updates an existing balance definition. * * PUT /api/balances/definitions/update * * Also accepts auth: ApiKey */ export const updateApiApiBalancesDefinitionsUpdate = async (args: UpdateApiApiBalancesDefinitionsUpdateArgs, options?: UpdateApiApiBalancesDefinitionsUpdateOptions) => { const {baseUrl = "https://api.intect.app", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/balances/definitions/update${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(intectBalanceDefinition, await res.json()) };