from dataclasses import dataclass
from typing import List, Dict, Any, TypeVar, Callable, Type, cast
from extensions.list import CoreList

from models.var import from_str, from_float


@dataclass
class EnvModel:
    cadFilePath: str
    outPath: str
    solidBodyPadding: float
    firstDetail: str
    sequencesFixed: list[list[str]]

    @staticmethod
    def from_dict(obj: Any) -> "EnvModel":
        assert isinstance(obj, dict)
        cadFilePath = from_str(obj.get("cadFilePath"))
        outPath = from_str(obj.get("outPath"))
        solidBodyPadding = from_float(obj.get("solidBodyPadding"))
        firstDetail = from_str(obj.get("firstDetail"))
        sequencesFixed = []
        sequencesFixedParse = CoreList(obj.get("sequencesFixed"))
        for el in sequencesFixedParse:
            sequencesFixed.append(el)

        restrictionsOnFasteners = CoreList(obj.get("restrictionsOnFasteners"))

        for el in restrictionsOnFasteners:
            for part in el["parts"]:
                sequencesFixed.append([part, el["fastener"]])
        return EnvModel(
            cadFilePath,
            outPath,
            solidBodyPadding,
            firstDetail,
            sequencesFixed,
        )

    def to_dict(self) -> dict:
        result: dict = {}
        result["cadFilePath"] = from_str(self.cadFilePath)
        result["outPath"] = from_str(self.outPath)
        result["solidBodyPadding"] = from_float(self.solidBodyPadding)
        result["firstDetail"] = from_str(self.firstDetail)
        result["sequencesFixed"] = self.sequencesFixed
        return result
