from product_api.dto import Part
from typing import (
    Dict,
    List,
    Optional,
)


# noinspection PyShadowingBuiltins
class SaleLine(object):
    def __init__(
        self,
        line_number,                    # type: int
        part,                           # type: Part
        level,                          # type: int
        item_id,                        # type: str
        item_price,                     # type: float
        quantity,                       # type: float
        default_qty,                    # type: int
        multiplied_qty=None,            # type: float
        added_qty=None,                 # type: Optional[float]
        overwritten_unit_price=None,    # type: Optional[float]
        comment=None,                   # type: Optional[str]
        service_period=None,            # type: Optional[str]
        seat=None,                      # type: Optional[int]
        custom_properties=None,         # type: Dict[str, str]
        discounts_applied=None,         # type: Optional[str]
    ):
        # type: (...) -> None

        self.line_number = line_number
        self.part = part
        self.level = level
        self.item_id = item_id
        self.item_price = item_price
        self.overwritten_unit_price = overwritten_unit_price
        self.quantity = quantity
        self.added_qty = added_qty
        self.default_qty = default_qty
        self.multiplied_qty = multiplied_qty
        self.comment = comment
        self.service_period = service_period
        self.seat = seat
        self.custom_properties = custom_properties
        self.discounts_applied = discounts_applied

        self.fraction_parent = None     # type: Optional[int]
        self.parent = None              # type: Optional[SaleLine]
        self.sons = None                # type: Optional[List[SaleLine]]

    def get_custom_property(
        self,   # type: SaleLine
        key,    # type: str
    ):
        # type: (...) -> Optional[str]

        return self.custom_properties.get(key, None)

    def get_line_id(
        self,   # type: SaleLine
    ):
        # type: (...) -> str

        return "{}.{}-{}.{}".format(
            self.line_number,
            self.level,
            self.item_id,
            self.part.part_code,
        )
