from application.domain import TableService  # noqa
from application.domain.ui import ScreenChanger, ScreenIdEnum  # noqa
from application.interactor.service import TableReleaser  # noqa
from typing import (
    Dict,
    Optional,
    Union,
)


class StartServiceInteractor(object):
    def __init__(self, screen_changer, table_service, table_releaser):
        # type: (ScreenChanger, TableService, TableReleaser) -> None
        self.screen_changer = screen_changer
        self.table_service = table_service
        self.table_releaser = table_releaser

    def execute(
        self,                       # type: StartServiceInteractor
        pos_id,                     # type: Union[int, str]
        table_id="",                # type: str
        seats="",                   # type: str
        name="",                    # type: str
        mode="",                    # type: str
        source_table_id="",         # type: str
        custom_properties=None,     # type: Optional[Dict[str, str]]
    ):
        # type: (...) -> str

        self.table_releaser.release_all(pos_id)
        ret = self.table_service.start_service(
            pos_id=pos_id,
            table_id=table_id,
            seats=seats,
            name=name,
            mode=mode,
            source_table_id=source_table_id,
            custom_properties=custom_properties,
        )
        return ret
