# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.featured_gallery_config_input import FeaturedGalleryConfigInput
from mixpeek.models.hero_config import HeroConfig
from mixpeek.models.page_meta import PageMeta
from mixpeek.models.page_tab_input import PageTabInput
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 UpdatePageRequest(BaseModel):
    """
    Request to update an existing Page (all fields optional).
    """ # noqa: E501
    slug: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=60)]] = None
    template: Optional[StrictStr] = None
    sections: Optional[List[SectionConfig]] = None
    custom_html: Optional[StrictStr] = None
    meta: Optional[PageMeta] = None
    hero: Optional[HeroConfig] = None
    theme: Optional[ThemeConfig] = None
    seo: Optional[SEOConfig] = None
    stats: Optional[List[StatItem]] = None
    featured_gallery: Optional[FeaturedGalleryConfigInput] = None
    tabs: Optional[List[PageTabInput]] = None
    password_secret_name: Optional[StrictStr] = None
    is_active: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["slug", "template", "sections", "custom_html", "meta", "hero", "theme", "seo", "stats", "featured_gallery", "tabs", "password_secret_name", "is_active"]

    @field_validator('slug')
    def slug_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[a-z0-9][a-z0-9-]*[a-z0-9]$", value):
            raise ValueError(r"must validate the regular expression /^[a-z0-9][a-z0-9-]*[a-z0-9]$/")
        return value

    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 UpdatePageRequest 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 UpdatePageRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "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": FeaturedGalleryConfigInput.from_dict(obj["featured_gallery"]) if obj.get("featured_gallery") is not None else None,
            "tabs": [PageTabInput.from_dict(_item) for _item in obj["tabs"]] if obj.get("tabs") is not None else None,
            "password_secret_name": obj.get("password_secret_name"),
            "is_active": obj.get("is_active")
        })
        return _obj


