from dataclasses import dataclass
from typing import Any, Dict, Optional

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
    required: bool = True
    description: str = None
    deprecated: Optional[bool] = None
    example: Any = None
    content: Dict[str, PathContentModel] = None

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

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

    def get_field_key(self, field_name: str) -> str:
        if field_name == 'path_in':
            return 'in'

        return super().get_field_key(field_name)
