# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.catalogs_feed_credentials import CatalogsFeedCredentials
from pinterestsdk.models.catalogs_feed_processing_schedule import CatalogsFeedProcessingSchedule
from pinterestsdk.models.catalogs_format import CatalogsFormat
from pinterestsdk.models.catalogs_status import CatalogsStatus
from pinterestsdk.models.nullable_currency import NullableCurrency
from pinterestsdk.models.product_availability_type import ProductAvailabilityType
from typing import Optional, Set
from typing_extensions import Self

class CatalogsFeedsUpdateRequest(BaseModel):
    """
    Request object for updating a feed.
    """ # noqa: E501
    credentials: Optional[CatalogsFeedCredentials] = None
    default_availability: Optional[ProductAvailabilityType] = None
    default_currency: Optional[NullableCurrency] = None
    format: Optional[CatalogsFormat] = None
    location: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="The URL where a feed is available for download. This URL is what Pinterest will use to download a feed for processing.")
    name: Optional[StrictStr] = Field(default=None, description="A human-friendly name associated to a given feed.")
    preferred_processing_schedule: Optional[CatalogsFeedProcessingSchedule] = None
    status: Optional[CatalogsStatus] = None
    __properties: ClassVar[List[str]] = ["credentials", "default_availability", "default_currency", "format", "location", "name", "preferred_processing_schedule", "status"]

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

        if not re.match(r"^(http|https|ftp|sftp):\/\/", value):
            raise ValueError(r"must validate the regular expression /^(http|https|ftp|sftp):\/\//")
        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 CatalogsFeedsUpdateRequest 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 credentials
        if self.credentials:
            _dict['credentials'] = self.credentials.to_dict()
        # override the default output from pydantic by calling `to_dict()` of preferred_processing_schedule
        if self.preferred_processing_schedule:
            _dict['preferred_processing_schedule'] = self.preferred_processing_schedule.to_dict()
        # set to None if credentials (nullable) is None
        # and model_fields_set contains the field
        if self.credentials is None and "credentials" in self.model_fields_set:
            _dict['credentials'] = None

        # set to None if default_availability (nullable) is None
        # and model_fields_set contains the field
        if self.default_availability is None and "default_availability" in self.model_fields_set:
            _dict['default_availability'] = None

        # set to None if default_currency (nullable) is None
        # and model_fields_set contains the field
        if self.default_currency is None and "default_currency" in self.model_fields_set:
            _dict['default_currency'] = None

        # set to None if preferred_processing_schedule (nullable) is None
        # and model_fields_set contains the field
        if self.preferred_processing_schedule is None and "preferred_processing_schedule" in self.model_fields_set:
            _dict['preferred_processing_schedule'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "credentials": CatalogsFeedCredentials.from_dict(obj["credentials"]) if obj.get("credentials") is not None else None,
            "default_availability": obj.get("default_availability"),
            "default_currency": obj.get("default_currency"),
            "format": obj.get("format"),
            "location": obj.get("location"),
            "name": obj.get("name"),
            "preferred_processing_schedule": CatalogsFeedProcessingSchedule.from_dict(obj["preferred_processing_schedule"]) if obj.get("preferred_processing_schedule") is not None else None,
            "status": obj.get("status")
        })
        return _obj


