# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.error_detail import ErrorDetail
from pinterestsdk.models.record_counts import RecordCounts
from pinterestsdk.models.user_list_operation_type import UserListOperationType
from typing import Optional, Set
from typing_extensions import Self

class CustomerListUpload(BaseModel):
    """
    CustomerListUpload
    """ # noqa: E501
    ad_account_id: Annotated[str, Field(strict=True)] = Field(description="Advertiser ID.")
    creation_time: StrictInt = Field(description="Customer List Upload creation_time. Epoch (seconds).")
    customer_list_id: Annotated[str, Field(strict=True)] = Field(description="ID of the customer list associated with this upload.")
    error_counts: Optional[List[ErrorDetail]] = Field(default=None, description="Error counts by error code")
    id: Annotated[str, Field(strict=True)] = Field(description="Customer List Upload ID.")
    operation: UserListOperationType
    record_counts: Optional[RecordCounts] = None
    state: StrictStr = Field(description="Workload processing state")
    updated_time: StrictInt = Field(description="Customer List Upload updated_time. Epoch (seconds).")
    __properties: ClassVar[List[str]] = ["ad_account_id", "creation_time", "customer_list_id", "error_counts", "id", "operation", "record_counts", "state", "updated_time"]

    @field_validator('ad_account_id')
    def ad_account_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

    @field_validator('customer_list_id')
    def customer_list_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

    @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

    @field_validator('state')
    def state_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['NOT_STARTED', 'RUNNING', 'PAUSED', 'SUCCEEDED', 'FAILED']):
            raise ValueError("must be one of enum values ('NOT_STARTED', 'RUNNING', 'PAUSED', 'SUCCEEDED', 'FAILED')")
        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 CustomerListUpload 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 error_counts (list)
        _items = []
        if self.error_counts:
            for _item_error_counts in self.error_counts:
                if _item_error_counts:
                    _items.append(_item_error_counts.to_dict())
            _dict['error_counts'] = _items
        # override the default output from pydantic by calling `to_dict()` of record_counts
        if self.record_counts:
            _dict['record_counts'] = self.record_counts.to_dict()
        # set to None if error_counts (nullable) is None
        # and model_fields_set contains the field
        if self.error_counts is None and "error_counts" in self.model_fields_set:
            _dict['error_counts'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "ad_account_id": obj.get("ad_account_id"),
            "creation_time": obj.get("creation_time"),
            "customer_list_id": obj.get("customer_list_id"),
            "error_counts": [ErrorDetail.from_dict(_item) for _item in obj["error_counts"]] if obj.get("error_counts") is not None else None,
            "id": obj.get("id"),
            "operation": obj.get("operation"),
            "record_counts": RecordCounts.from_dict(obj["record_counts"]) if obj.get("record_counts") is not None else None,
            "state": obj.get("state"),
            "updated_time": obj.get("updated_time")
        })
        return _obj


