import {z} from 'zod' export type IntectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalancesDetail = {BalancePeriodId?: (number | null) | undefined, VacationPeriodName?: string | undefined, EarnedDaysAdjustment?: (number | null) | undefined, SpentDaysAdjustment?: (number | null) | undefined, Amount?: (number | null) | undefined, RemainingDaysAdjustment?: (number | null) | undefined, ActualEarnedDaysAdjustment?: (number | null) | undefined, ValuePerDayAdjustment?: (number | null) | undefined, TopUpAmount?: (number | null) | undefined, UnpaidDaysAdjustment?: (number | null) | undefined, VariableSalaryAdjustment?: (number | null) | undefined, VariableVacationSalaryAdjustment?: (number | null) | undefined, VacationDegreeOfEmployment?: (number | null) | undefined}; export type IntectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalances = {UserEmploymentId?: number | undefined, PerDate?: string | undefined, Details?: Array | undefined, AdvanceVacationDetail?: IntectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalancesDetail | undefined, IncludeDrafts?: boolean | undefined}; export type CreateApiApiBalancesSevacationArgs = {body: IntectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalances}; export type CreateApiApiBalancesSevacationOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalancesDetail = z.object({BalancePeriodId: z.number().int().nullable().optional(), VacationPeriodName: z.string().optional(), EarnedDaysAdjustment: z.number().nullable().optional(), SpentDaysAdjustment: z.number().nullable().optional(), Amount: z.number().nullable().optional(), RemainingDaysAdjustment: z.number().nullable().optional(), ActualEarnedDaysAdjustment: z.number().nullable().optional(), ValuePerDayAdjustment: z.number().nullable().optional(), TopUpAmount: z.number().nullable().optional(), UnpaidDaysAdjustment: z.number().nullable().optional(), VariableSalaryAdjustment: z.number().nullable().optional(), VariableVacationSalaryAdjustment: z.number().nullable().optional(), VacationDegreeOfEmployment: z.number().nullable().optional()}); export const intectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalances = z.object({UserEmploymentId: z.number().int().optional(), PerDate: z.string().optional(), Details: z.array(intectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalancesDetail).optional(), AdvanceVacationDetail: intectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalancesDetail.optional(), IncludeDrafts: z.boolean().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 }; /** * Submits a change to update Swedish vacation balances for an employee per a date. * * POST /api/balances/sevacation * * Also accepts auth: ApiKey */ export const createApiApiBalancesSevacation = async (args: CreateApiApiBalancesSevacationArgs, options?: CreateApiApiBalancesSevacationOptions) => { 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/sevacation${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(intectBusinessLogicSeBalanceAdjustmentsLogicSwedishUseremploymentVacationBalances, await res.json()) };