from typing import (
    Dict,
    List,
    Optional,
)

from ._SuggestiveSellingType import SuggestiveSellingType


class SuggestiveSellingEntry:

    def __init__(
        self,
        id,                     # type: int
        highlight_first,        # type: bool
        suggested_product_list,  # type: List[str]
    ):
        # type: (...) -> None

        self.id = id
        self.highlight_first = highlight_first
        self.suggested_product_list = suggested_product_list

    @classmethod
    def from_dict(
        cls,
        data,   # type: Dict[str, object]
    ):
        # type: (...) -> SuggestiveSellingEntry

        return cls(
            id=data["id"],
            highlight_first=data.get("highlightFirst", False),
            suggested_product_list=data.get("suggestedProductList", []),
        )

    def to_dict(
        self,
    ):
        # type: (...) -> Dict[str, object]

        return {
            "id": self.id,
            "highlightFirst": self.highlight_first,
            "suggestedProductList": self.suggested_product_list,
        }


class SuggestiveSelling:

    def __init__(
        self,
        on_start,   # type: Optional[SuggestiveSellingEntry]
        on_total,   # type: Optional[SuggestiveSellingEntry]
        on_sale,    # type: Dict[str, SuggestiveSellingEntry]
    ):
        # type: (...) -> None

        self.on_start = on_start
        self.on_total = on_total
        self.on_sale = on_sale

    @classmethod
    def from_dict(
        cls,
        data,   # type: Dict[str, object]
    ):
        # type: (...) -> SuggestiveSelling

        on_start_data = data.get(SuggestiveSellingType.ON_START.value) or None
        on_total_data = data.get(SuggestiveSellingType.ON_TOTAL.value) or None
        on_sale_data = data.get(SuggestiveSellingType.ON_SALE.value) or {}
        return cls(
            on_start=SuggestiveSellingEntry.from_dict(on_start_data) if on_start_data else None,
            on_total=SuggestiveSellingEntry.from_dict(on_total_data) if on_total_data else None,
            on_sale={
                key: SuggestiveSellingEntry.from_dict(val)
                for key, val in on_sale_data.items()
            },
        )

    def to_dict(
        self,
    ):
        # type: (...) -> Dict[str, object]

        return {
            SuggestiveSellingType.ON_START.value: self.on_start.to_dict() if self.on_start else {},
            SuggestiveSellingType.ON_TOTAL.value: self.on_total.to_dict() if self.on_total else {},
            SuggestiveSellingType.ON_SALE.value: {key: val.to_dict() for key, val in self.on_sale.items()},
        }
