# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 0.81.1
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List
from mixpeek.models.featured_gallery_config_output import FeaturedGalleryConfigOutput
from mixpeek.models.hero_config import HeroConfig
from mixpeek.models.page_meta import PageMeta
from mixpeek.models.page_tab_output import PageTabOutput
from mixpeek.models.section_config import SectionConfig
from mixpeek.models.seo_config import SEOConfig
from mixpeek.models.stat_item import StatItem
from mixpeek.models.theme_config import ThemeConfig
from typing import Optional, Set
from typing_extensions import Self

class PageResponse(BaseModel):
    """
    Response model for a Page.
    """ # noqa: E501
    page_id: StrictStr
    slug: StrictStr
    template: StrictStr
    sections: List[SectionConfig]
    custom_html: StrictStr
    meta: PageMeta
    hero: HeroConfig
    theme: ThemeConfig
    seo: SEOConfig
    stats: List[StatItem]
    featured_gallery: FeaturedGalleryConfigOutput
    tabs: List[PageTabOutput]
    password_protected: StrictBool
    is_active: StrictBool
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["page_id", "slug", "template", "sections", "custom_html", "meta", "hero", "theme", "seo", "stats", "featured_gallery", "tabs", "password_protected", "is_active", "created_at", "updated_at"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PageResponse from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in sections (list)
        _items = []
        if self.sections:
            for _item_sections in self.sections:
                if _item_sections:
                    _items.append(_item_sections.to_dict())
            _dict['sections'] = _items
        # override the default output from pydantic by calling `to_dict()` of meta
        if self.meta:
            _dict['meta'] = self.meta.to_dict()
        # override the default output from pydantic by calling `to_dict()` of hero
        if self.hero:
            _dict['hero'] = self.hero.to_dict()
        # override the default output from pydantic by calling `to_dict()` of theme
        if self.theme:
            _dict['theme'] = self.theme.to_dict()
        # override the default output from pydantic by calling `to_dict()` of seo
        if self.seo:
            _dict['seo'] = self.seo.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in stats (list)
        _items = []
        if self.stats:
            for _item_stats in self.stats:
                if _item_stats:
                    _items.append(_item_stats.to_dict())
            _dict['stats'] = _items
        # override the default output from pydantic by calling `to_dict()` of featured_gallery
        if self.featured_gallery:
            _dict['featured_gallery'] = self.featured_gallery.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in tabs (list)
        _items = []
        if self.tabs:
            for _item_tabs in self.tabs:
                if _item_tabs:
                    _items.append(_item_tabs.to_dict())
            _dict['tabs'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PageResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "page_id": obj.get("page_id"),
            "slug": obj.get("slug"),
            "template": obj.get("template"),
            "sections": [SectionConfig.from_dict(_item) for _item in obj["sections"]] if obj.get("sections") is not None else None,
            "custom_html": obj.get("custom_html"),
            "meta": PageMeta.from_dict(obj["meta"]) if obj.get("meta") is not None else None,
            "hero": HeroConfig.from_dict(obj["hero"]) if obj.get("hero") is not None else None,
            "theme": ThemeConfig.from_dict(obj["theme"]) if obj.get("theme") is not None else None,
            "seo": SEOConfig.from_dict(obj["seo"]) if obj.get("seo") is not None else None,
            "stats": [StatItem.from_dict(_item) for _item in obj["stats"]] if obj.get("stats") is not None else None,
            "featured_gallery": FeaturedGalleryConfigOutput.from_dict(obj["featured_gallery"]) if obj.get("featured_gallery") is not None else None,
            "tabs": [PageTabOutput.from_dict(_item) for _item in obj["tabs"]] if obj.get("tabs") is not None else None,
            "password_protected": obj.get("password_protected"),
            "is_active": obj.get("is_active"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


