from typing import Optional

from posot import OrderTaker
from sysactions import (
    get_model,
    get_posot,
)

from application.model.order import Order


class VerifyAndRemoveBenefitsUnitOfWork(object):
    def __init__(
        self,
        pos_id,         # type: int
        order,          # type: Order
        pos_ot=None,    # type: Optional[OrderTaker]
    ):
        # type: (...) -> None

        self.pos_id = pos_id
        self.order = order
        self.model = None
        self._pos_ot = pos_ot

    @property
    def pos_ot(
        self,
    ):
        # type: (...) -> OrderTaker

        if self._pos_ot is not None:
            return self._pos_ot

        if self.model is None:
            self.model = get_model(posid=self.pos_id)
        return get_posot(model=self.model)
