from typing import (
    Dict,
    List,
)

from ._UpdatableEntity import UpdatableEntity


class Tender(UpdatableEntity):
    def __init__(
        self,
        tender_id: int,
        tender_type: int,
        tender_name: str,
        tender_amount: float,
        change_amount: float,
        details: Dict[str, str],
    ):
        self.tender_id = tender_id
        self.tender_type = tender_type
        self.tender_name = tender_name
        self.tender_amount = tender_amount
        self.change_amount = change_amount
        self.details = details

    @classmethod
    def create_from_dict(cls, record: dict):
        tender = cls(
            tender_id=record["id"],
            tender_type=int(record["tenderType"]),
            tender_name=record["tenderDesc"],
            tender_amount=record["tenderAmount"],
            change_amount=record.get("changeAmount", 0.0),
            details=record.get("details", {}),
        )
        return tender

    @classmethod
    def create_list_from_list(cls, records: List[dict]):
        ret = []
        for record in records:
            ret.append(cls.create_from_dict(record=record))

        return ret

    def update(self, new_data: 'Tender'):
        self.tender_type = new_data.tender_type
        self.tender_name = new_data.tender_name
        self.tender_amount = new_data.tender_amount
        self.change_amount = new_data.change_amount
        self.details = new_data.details

    def __id__(self):
        return self.tender_id
