from dataclasses import dataclass
from typing import Dict

from ._BaseModel import BaseModel
from ._PathContentModel import PathContentModel
from ._PathParameterInEnum import PathParameterInEnum
from ._SchemaPropertyModel import SchemaPropertyModel
from ..utils import set_dict_path_value


@dataclass
class PathParameterModel(BaseModel):
    path_in: PathParameterInEnum
    name: str
    schema: SchemaPropertyModel | None = None
    required: bool = True
    description: str | None = None
    contents: Dict[str, PathContentModel] | None = None

    def add_content(self, content_type: str, content: PathContentModel) -> None:
        if self.contents is None:
            self.contents = {}

        set_dict_path_value(
            dict_value=self.contents,
            path=[content_type],
            value=content
        )

    def to_dict(self) -> dict:
        return {
            "in": self.path_in,
            "name": self.name,
            "schema": self.schema,
            "required": self.required,
            "description": self.description,
            "content": self.contents,
        }
