import {z} from 'zod' export type LedgerAccount = {id?: string | undefined, type?: string | undefined, attributes?: ({created_at?: string | undefined, updated_at?: string | undefined, number?: string | undefined, name?: string | undefined, report_type?: string | undefined, fixed_type?: ('cash' | 'bank' | 'pin' | 'psp' | 'safe' | 'booking' | 'channel' | 'pos' | 'owner' | 'pre_invoiced_turnover' | 'vat_low_payable' | 'vat_high_payable' | 'settlements' | 'batch' | 'vouchers' | 'other_parks' | 'advances' | 'uncategorized_payments' | 'security_deposits' | 'security_deposits_damages' | 'payment_difference' | 'cash_difference' | 'rent' | 'uncategorized_expenses' | 'uncategorized_turnover') | undefined, current_vat_rate?: number | undefined}) | undefined, relationships?: ({vat_code?: ({data?: ({id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}) | undefined}) | undefined}) | undefined, meta?: ({temp_id?: string | undefined}) | undefined}; export type UsedMaterial = {id?: string | undefined, type?: string | undefined, attributes?: ({quantity?: number | undefined, description?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined}) | undefined, relationships?: ({task_cost?: ({data?: ({id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}) | undefined}) | undefined, todo?: ({data?: ({id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}) | undefined}) | undefined}) | undefined, meta?: ({temp_id?: string | undefined}) | undefined}; export type CreateApiV3AdministrationsAdministrationIdTaskCostsArgs = {administration_id: string, 'fields[task_cost]'?: string | undefined, include?: string | undefined, 'Accept-Language'?: string | undefined, body: {data?: ({type?: string | undefined, attributes?: ({description?: ({cs?: string | undefined, 'da-DK'?: string | undefined, de?: string | undefined, 'de-AT'?: string | undefined, 'de-CH'?: string | undefined, 'en-US'?: string | undefined, 'en-GB'?: string | undefined, es?: string | undefined, fr?: string | undefined, 'fr-BE'?: string | undefined, 'fr-LU'?: string | undefined, it?: string | undefined, nb?: string | undefined, nl?: string | undefined, 'nl-BE'?: string | undefined, pl?: string | undefined, pt?: string | undefined, tr?: string | undefined, en?: string | undefined, da?: string | undefined}) | undefined, price?: number | undefined}) | undefined, relationships?: ({account?: ({data?: ({id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}) | undefined}) | undefined, used_materials?: ({data?: (Array<{id?: string | undefined, type?: string | undefined, meta?: ({temp_id?: string | undefined, method?: string | undefined}) | undefined}>) | undefined}) | undefined}) | undefined, meta?: ({temp_id?: string | undefined}) | undefined}) | undefined, included?: (Array) | undefined}}; export type CreateApiV3AdministrationsAdministrationIdTaskCostsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskCost = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({description: z.object({cs: z.string().optional(), "da-DK": z.string().optional(), de: z.string().optional(), "de-AT": z.string().optional(), "de-CH": z.string().optional(), "en-US": z.string().optional(), "en-GB": z.string().optional(), es: z.string().optional(), fr: z.string().optional(), "fr-BE": z.string().optional(), "fr-LU": z.string().optional(), it: z.string().optional(), nb: z.string().optional(), nl: z.string().optional(), "nl-BE": z.string().optional(), pl: z.string().optional(), pt: z.string().optional(), tr: z.string().optional(), en: z.string().optional(), da: z.string().optional()}).optional(), price: z.number().optional(), archived: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), relationships: z.object({account: z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()}).optional()}).optional(), used_materials: z.object({data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()})).optional()}).optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const ledgerAccount = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({created_at: z.string().optional(), updated_at: z.string().optional(), number: z.string().optional(), name: z.string().optional(), report_type: z.string().optional(), fixed_type: z.enum(["cash", "bank", "pin", "psp", "safe", "booking", "channel", "pos", "owner", "pre_invoiced_turnover", "vat_low_payable", "vat_high_payable", "settlements", "batch", "vouchers", "other_parks", "advances", "uncategorized_payments", "security_deposits", "security_deposits_damages", "payment_difference", "cash_difference", "rent", "uncategorized_expenses", "uncategorized_turnover"]).optional(), current_vat_rate: z.number().optional()}).optional(), relationships: z.object({vat_code: z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()}).optional()}).optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const usedMaterial = z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({quantity: z.number().int().optional(), description: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), relationships: z.object({task_cost: z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()}).optional()}).optional(), todo: z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), meta: z.object({temp_id: z.string().optional(), method: z.string().optional()}).optional()}).optional()}).optional()}).optional(), meta: z.object({temp_id: z.string().optional()}).optional()}); export const createApiV3AdministrationsAdministrationIdTaskCostsResponse = z.object({data: taskCost.optional(), included: z.array(z.union([ledgerAccount, usedMaterial])).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 }; /** * POST task_cost * * POST /v3/administrations/{administration_id}/task_costs * * Also accepts auth: OAuth2 */ export const createApiV3AdministrationsAdministrationIdTaskCosts = async (args: CreateApiV3AdministrationsAdministrationIdTaskCostsArgs, options?: CreateApiV3AdministrationsAdministrationIdTaskCostsOptions) => { const {baseUrl = "https://api.bookingexperts.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/vnd.api+json") headers.set('accept', "application/vnd.api+json") if (args['fields[task_cost]'] != null) query.append("fields[task_cost]", String(args['fields[task_cost]'])) if (args.include != null) query.append("include", String(args.include)) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/administrations/${encodeURIComponent(String(args.administration_id))}/task_costs${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(createApiV3AdministrationsAdministrationIdTaskCostsResponse, await res.json()) };