export type MonetaryValueModel = {amount: number, currency: string}; export type RateRestrictionsModel = {minLengthOfStay?: (number | null) | undefined, maxLengthOfStay?: (number | null) | undefined, closed: boolean, closedOnArrival: boolean, closedOnDeparture: boolean}; export type ReplaceRateModel = {from: string, to: string, price?: MonetaryValueModel | undefined, restrictions?: RateRestrictionsModel | undefined}; export type ReplaceRateListModel = {rates: Array}; export type UpdateApiRateplanV1RatePlansIdRatesArgs = {id: string, body: ReplaceRateListModel}; export type UpdateApiRateplanV1RatePlansIdRatesOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Initializes and changes the rates for the rate plan. * * PUT /rateplan/v1/rate-plans/{id}/rates */ export const updateApiRateplanV1RatePlansIdRates = async (args: UpdateApiRateplanV1RatePlansIdRatesArgs, options: UpdateApiRateplanV1RatePlansIdRatesOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/rateplan/v1/rate-plans/${encodeURIComponent(String(args.id))}/rates${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 undefined };