import {z} from 'zod' export type CityTaxSubcategoryAgeModel = {min: number, max: number}; export type CityTaxSubcategoryModel = {name: {[key: string]: string | null}, value: number, age: CityTaxSubcategoryAgeModel}; export type CityTaxPricingRuleModel = {value: number, maxPrice: number}; export type DistributionChannelTaxConfigModel = {channelCode: 'Direct' | 'BookingCom' | 'Ibe' | 'ChannelManager' | 'Expedia' | 'Homelike' | 'Hrs' | 'AltoVita' | 'DesVu' | 'Gimsi', sources?: (Array | null) | undefined, remittanceResponsibility?: ('Hotel' | 'Ota' | null) | undefined}; export type CityTaxConfigModel = {distributionChannel?: DistributionChannelTaxConfigModel | undefined}; export type CreateCityTaxModel = {name: {[key: string]: string | null}, description: {[key: string]: string | null}, propertyId: string, type: 'PercentOfGross' | 'PercentOfNet' | 'PerRoomPerNight' | 'PerPersonPerNight' | 'PerPersonPerNightBasedOnNetPrice' | 'PerPersonPerNightBasedOnGrossPrice', taxHandlingType: 'BeforeTax' | 'AfterTax', value: number, vatType: 'Null' | 'VeryReduced' | 'Reduced' | 'Normal' | 'Without' | 'Special' | 'Special1' | 'Special2' | 'ReducedCovid19' | 'NormalCovid19' | 'Mixed', code?: (string | null) | undefined, priority?: (number | null) | undefined, includeCityTaxInRateAmount?: (boolean | null) | undefined, limit?: (number | null) | undefined, subcategories?: (Array | null) | undefined, pricingRules?: (Array | null) | undefined, ignoredFor?: (Array | null) | undefined}; export type CreateApiSettingsV1CityTaxArgs = {'Idempotency-Key'?: string | undefined, body: CreateCityTaxModel}; export type CreateApiSettingsV1CityTaxOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const cityTaxCreatedModel = z.object({id: z.string()}); 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 }; /** * Create a city tax. * * POST /settings/v1/city-tax */ export const createApiSettingsV1CityTax = async (args: CreateApiSettingsV1CityTaxArgs, options: CreateApiSettingsV1CityTaxOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/settings/v1/city-tax${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(cityTaxCreatedModel, await res.json()) };