from typing import (
    List,
    Optional,
)
from ._CustomProperty import CustomProperty
from ._Tender import Tender
from ._SaleLine import SaleLine


class Order(object):
    def __init__(
        self,                         # type: Order
        order_id=None,                # type: int
        state=None,                   # type: Optional[str]
        total_amount=None,            # type: Optional[float]
        total_gross=None,             # type: Optional[float]
        discount_amount=None,         # type: Optional[float]
        total_tender=None,            # type: Optional[float]
        total_after_discount=None,    # type: Optional[float]
        sale_lines=None,              # type: Optional[List[SaleLine]]
        custom_properties=None,       # type: Optional[List[CustomProperty]]
        tenders=None                  # type: Optional[List[Tender]]
    ):
        # type: (...) -> None

        self.order_id = order_id
        self.state = state
        self.total_amount = total_amount
        self.total_gross = total_gross
        self.discount_amount = discount_amount
        self.total_tender = total_tender
        self.total_after_discount = total_after_discount
        self.total_gross = total_gross
        self.sale_lines = sale_lines or []
        self.custom_properties = custom_properties or []
        self.tenders = tenders or []

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

        for custom_property in self.custom_properties:
            if custom_property.key == key:
                return custom_property

        return None
