import {z} from 'zod' export type IntectBusinessLogicNoVacationBalanceLogicUserEmploymentVacationDetail = {UserEmploymentId?: number | undefined, UserEmploymentName?: string | undefined, WorkDaysPerWeek?: number | undefined, VacationEarningPercentage?: string | undefined, SeniorVacationEarningPercentage?: string | undefined, VacationEarned?: (number | null) | undefined, SeniorVacationEarned?: (number | null) | undefined, VacationPaidOut?: (number | null) | undefined, SeniorVacationPaidOut?: (number | null) | undefined, VacationRemaining?: (number | null) | undefined, VacationDaysEarned?: (number | null) | undefined, SeniorVacationDaysEarned?: (number | null) | undefined, VacationDaysSpent?: (number | null) | undefined, SeniorVacationDaysSpent?: (number | null) | undefined, VacationDaysRemaining?: (number | null) | undefined, SpentDaysAdjustment?: (number | null) | undefined, SeniorDaysSpentAdjustment?: (number | null) | undefined}; export type IntectBusinessLogicNoVacationBalanceLogicNorwegianCompanyVacationBalances = {CompanyId?: number | undefined, BalancePeriodId?: number | undefined, PerDate?: string | undefined, VacationPayoutMethodId?: number | undefined, IncludeInactive?: boolean | undefined, IncludeEmpty?: boolean | undefined, UserEmploymentVacationDetails?: Array | undefined}; export type CreateApiApiBalancesNovacationAdjustmentsArgs = {body: IntectBusinessLogicNoVacationBalanceLogicNorwegianCompanyVacationBalances}; export type CreateApiApiBalancesNovacationAdjustmentsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectBusinessLogicNoVacationBalanceLogicUserEmploymentVacationDetail = z.object({UserEmploymentId: z.number().int().optional(), UserEmploymentName: z.string().optional(), WorkDaysPerWeek: z.number().int().optional(), VacationEarningPercentage: z.string().optional(), SeniorVacationEarningPercentage: z.string().optional(), VacationEarned: z.number().nullable().optional(), SeniorVacationEarned: z.number().nullable().optional(), VacationPaidOut: z.number().nullable().optional(), SeniorVacationPaidOut: z.number().nullable().optional(), VacationRemaining: z.number().nullable().optional(), VacationDaysEarned: z.number().int().nullable().optional(), SeniorVacationDaysEarned: z.number().int().nullable().optional(), VacationDaysSpent: z.number().nullable().optional(), SeniorVacationDaysSpent: z.number().nullable().optional(), VacationDaysRemaining: z.number().nullable().optional(), SpentDaysAdjustment: z.number().int().nullable().optional(), SeniorDaysSpentAdjustment: z.number().int().nullable().optional()}); export const intectBusinessLogicNoVacationBalanceLogicNorwegianCompanyVacationBalances = z.object({CompanyId: z.number().int().optional(), BalancePeriodId: z.number().int().optional(), PerDate: z.string().optional(), VacationPayoutMethodId: z.number().int().optional(), IncludeInactive: z.boolean().optional(), IncludeEmpty: z.boolean().optional(), UserEmploymentVacationDetails: z.array(intectBusinessLogicNoVacationBalanceLogicUserEmploymentVacationDetail).optional()}); export const createApiApiBalancesNovacationAdjustmentsResponse = z.array(intectBusinessLogicNoVacationBalanceLogicNorwegianCompanyVacationBalances); 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 Norwegian vacation balances with given adjustments and returns the outcome for the specified parameters * * POST /api/balances/novacation/adjustments * * Also accepts auth: ApiKey */ export const createApiApiBalancesNovacationAdjustments = async (args: CreateApiApiBalancesNovacationAdjustmentsArgs, options?: CreateApiApiBalancesNovacationAdjustmentsOptions) => { 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/novacation/adjustments${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(createApiApiBalancesNovacationAdjustmentsResponse, await res.json()) };