from sysactions import action, show_messagebox
from typing import List

from application.interactor import OrderInteractor


@action
def order_state_is_valid(
    pos_id,             # type: str
    state,              # type: str | List[str]
    table_id=None,      # type: str
):
    # type: (...) -> bool

    order = OrderInteractor(pos_id=pos_id).get_order_picture()

    if order is not None and order.get('state') in state:
        return True

    if table_id in ['', None]:
        from ..functions.do_store_order import doStoreOrder
        doStoreOrder(pos_id=pos_id)
        return False

    from table_actions import store_table_order
    store_table_order(
        pos_id=pos_id,
        table_id=table_id,
    )

    return False
