import json
import logging

from typing import (
    Any,
    Dict,
    List,
    Union,
)

from application.domain import TableService


class SectorOperatorInteractor(object):
    def __init__(
        self,
        table_service,  # type: TableService
    ):
        # type: (...) -> None

        self.logger = logging.getLogger(name="PosActions")
        self.table_service = table_service

    def get_sectors(
        self,
        pos_id,     # type: Any[Union[str, int]]
    ):
        # type: (...) -> List[str]

        return self.table_service.get_sectors(pos_id=pos_id)

    def get_operator_sector_info(
        self,
        pos_id,     # type: Any[Union[str, int]]
    ):
        # type: (...) -> Dict[str, List[int]]

        return self.table_service.get_operator_sector_info(pos_id=pos_id)

    def update_operator_sector_info(
        self,
        pos_id,         # type: Any[Union[str, int]]
        update_info,    # type: Dict[str, Dict]
    ):
        # type: (...) -> bool

        json_info = json.dumps(update_info) if update_info else "{}"
        return self.table_service.update_operator_sector_info(
            pos_id=pos_id,
            update_info=json_info,
        )
