from api.order import get_order_service
from application.domain import OrderManager, SaleLine  # noqa
from sysactions import get_posot, get_model


class MsgBusOrderManager(OrderManager):

    def recall_order(self, pos_id, order_id):
        order_service = get_order_service(pos_id=pos_id)
        order_service.recall_order(order_id=order_id)

    def store_order(self, pos_id):
        order_service = get_order_service(pos_id=pos_id)
        order_service.store_order()

    def change_line_seat(self, pos_id, sale_line, seat_number):
        # type: (str, SaleLine, str) -> None

        model = get_model(pos_id)
        pos_ot = get_posot(model)

        pos_ot.setOrderCustomProperty(
            "seat",
            str(seat_number),
            sale_line.order_id,
            sale_line.line_number,
            sale_line.item_id,
            sale_line.level,
            sale_line.part_code
        )

    def get_current_order_state(self, pos_id):
        order_service = get_order_service(pos_id=pos_id)

        order_picture = order_service.get_order_picture()
        if order_picture is not None:
            return order_picture.get("state")
        return None
