from __future__ import annotations
from typing import Any, ClassVar, TYPE_CHECKING
if TYPE_CHECKING:
from decimal import Decimal
from onegov.form import Form
from onegov.reservation import Reservation, Resource
[docs]
PRICING_SCHEMES: dict[str, type[ResourcePricingScheme]] = {}
[docs]
class ResourcePricingScheme:
""" Defines a complex pricing scheme, that cannot be expressed using
the regular available configuration knobs.
These are generally extremely specific to single customers and while
they do feature parameters that can be set per resource, the formula
itself is static and should not be changed after its inital creation.
If the formula needs to change we need to create a new scheme instead,
so old reservations can keep relying on the old scheme.
"""
[docs]
def __init_subclass__(
cls,
name: str | None = None,
label: str | None = None,
**kwargs: Any,
) -> None:
if name is not None:
assert name not in PRICING_SCHEMES
assert label is not None
cls.name = name
cls.label = label
PRICING_SCHEMES[name] = cls
super().__init_subclass__(**kwargs)
@classmethod
[docs]
def reservation_unit_price(
cls,
reservation: Reservation,
resource: Resource,
submission_data: dict[str, Any] | None
) -> Decimal | None:
""" Calculates the unit price for the given reservation. """
raise NotImplementedError
@classmethod