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

from ._BaseModel import BaseModel
from ._PathContentModel import PathContentModel
from ..utils import set_dict_path_value


@dataclass
class RequestBodyModel(BaseModel):
    content: Dict[str, PathContentModel] = field(default_factory=dict)
    description: Optional[str] = None
    required: bool = True

    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 to_dict(self) -> dict:
        return {
            "content": self.content,
            "description": self.description,
            "required": self.required,
        }
