# 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 pydantic import BaseModel, ConfigDict, Field, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.bulk_download_request_campaign_filter import BulkDownloadRequestCampaignFilter
from pinterestsdk.models.bulk_entity_type import BulkEntityType
from pinterestsdk.models.bulk_output_format import BulkOutputFormat
from typing import Optional, Set
from typing_extensions import Self

class BulkDownloadRequest(BaseModel):
    """
    Ad entities to get in bulk request.
    """ # noqa: E501
    campaign_filter: Optional[BulkDownloadRequestCampaignFilter] = None
    entity_ids: Optional[List[Annotated[str, Field(strict=True)]]] = Field(default=None, description="All entities specified by these IDs as well as their children and grandchildren will be downloaded if the entity type is one of the types requested to be downloaded.")
    entity_types: Optional[Annotated[List[BulkEntityType], Field(min_length=1, max_length=6)]] = Field(default=None, description="All entity types specified will be downloaded. Fewer types result in faster downloads.")
    output_format: Optional[BulkOutputFormat] = 'JSON'
    updated_since: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Unix UTC timestamp to retrieve all entities that have changed since this time.")
    __properties: ClassVar[List[str]] = ["campaign_filter", "entity_ids", "entity_types", "output_format", "updated_since"]

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

        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 BulkDownloadRequest 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 campaign_filter
        if self.campaign_filter:
            _dict['campaign_filter'] = self.campaign_filter.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "campaign_filter": BulkDownloadRequestCampaignFilter.from_dict(obj["campaign_filter"]) if obj.get("campaign_filter") is not None else None,
            "entity_ids": obj.get("entity_ids"),
            "entity_types": obj.get("entity_types"),
            "output_format": obj.get("output_format") if obj.get("output_format") is not None else 'JSON',
            "updated_since": obj.get("updated_since")
        })
        return _obj


