# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.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, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.board_media import BoardMedia
from pinterestsdk.models.board_owner import BoardOwner
from pinterestsdk.models.board_update_privacy import BoardUpdatePrivacy
from typing import Optional, Set
from typing_extensions import Self

class BoardWithUpdatePrivacy(BaseModel):
    """
    BoardWithUpdatePrivacy
    """ # noqa: E501
    board_pins_modified_at: Optional[datetime] = Field(default=None, description="Date and time of last board pins modified.")
    collaborator_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Count of collaborators on the board.")
    created_at: Optional[datetime] = Field(default=None, description="Date and time of board creation.")
    description: Optional[StrictStr] = None
    follower_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Board follower count.")
    id: Annotated[str, Field(strict=True)]
    is_ads_only: Optional[StrictBool] = Field(default=False, description="If set to `true`, the board will be ad-only and can store ad-only Pins.")
    media: Optional[BoardMedia] = Field(default=None, description="Board media.")
    name: StrictStr = Field(description="     Name of the board.      **Note:** If you create an ad-only board by setting `is_ads_only`     to `true`, the board name automatically becomes \"Ad-only Pins\".")
    owner: Optional[BoardOwner] = None
    pin_count: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Count of Pins on the board.")
    privacy: Optional[BoardUpdatePrivacy] = None
    __properties: ClassVar[List[str]] = ["board_pins_modified_at", "collaborator_count", "created_at", "description", "follower_count", "id", "is_ads_only", "media", "name", "owner", "pin_count", "privacy"]

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+$/")
        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 BoardWithUpdatePrivacy 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "board_pins_modified_at",
            "collaborator_count",
            "created_at",
            "follower_count",
            "id",
            "media",
            "owner",
            "pin_count",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of media
        if self.media:
            _dict['media'] = self.media.to_dict()
        # override the default output from pydantic by calling `to_dict()` of owner
        if self.owner:
            _dict['owner'] = self.owner.to_dict()
        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "board_pins_modified_at": obj.get("board_pins_modified_at"),
            "collaborator_count": obj.get("collaborator_count"),
            "created_at": obj.get("created_at"),
            "description": obj.get("description"),
            "follower_count": obj.get("follower_count"),
            "id": obj.get("id"),
            "is_ads_only": obj.get("is_ads_only") if obj.get("is_ads_only") is not None else False,
            "media": BoardMedia.from_dict(obj["media"]) if obj.get("media") is not None else None,
            "name": obj.get("name"),
            "owner": BoardOwner.from_dict(obj["owner"]) if obj.get("owner") is not None else None,
            "pin_count": obj.get("pin_count"),
            "privacy": obj.get("privacy")
        })
        return _obj


