from datetime import time
from typing import (
    Dict,
    Optional,
    Set,
    Union,
)


class ServicePeriod(object):

    def __init__(
        self,               # type: ServicePeriod
        id,                 # type: int
        name,               # type: str
        start_hour,         # type: str
        end_hour,           # type: str
        week_days,          # type: str
        price_list_id,      # type: int
        price_list_abbr,    # type: str
    ):
        # type: (...) -> None

        self.id = id
        self.name = name
        self.start_hour = start_hour
        self.end_hour = end_hour
        self.week_days = week_days
        self.price_list_id = price_list_id
        self.price_list_abbr = price_list_abbr
        self.parsed_start = None   # type: Optional[time]
        self.parsed_end = None     # type: Optional[time]
        self.active_days = set()   # type: Set[str]

    def to_dict(self):
        # type: () -> Dict[str, Union[int, str]]

        return {
            "id": self.id,
            "name": self.name,
            "startHour": self.start_hour,
            "endHour": self.end_hour,
            "weekDays": self.week_days,
            "priceListId": self.price_list_id,
            "priceListAbbr": self.price_list_abbr,
        }

    @staticmethod
    def build_from_dict(
        data_dict,  # type: Dict
    ):
        # type: (...) -> ServicePeriod

        return ServicePeriod(
            id=data_dict["id"],
            name=data_dict.get("name", ""),
            start_hour=data_dict["startHour"],
            end_hour=data_dict["endHour"],
            week_days=data_dict["weekDays"],
            price_list_id=data_dict.get("priceListId", 0),
            price_list_abbr=data_dict.get("priceListAbbr", ""),
        )
