# coding: utf-8

"""
    CampaignManagementService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union, Set
from openapi_client.models.campaign.batch_error import BatchError
from openapi_client.models.campaign.editorial_error import EditorialError
from openapi_client.models.campaign.operation_error import OperationError
from typing_extensions import Self

class EditorialApiFaultDetail(BaseModel):
    """
    EditorialApiFaultDetail
    """ # noqa: E501
    editorial_errors: Optional[List[Optional[EditorialError]]] = Field(default=None, alias="EditorialErrors")
    batch_errors: Optional[List[Optional[BatchError]]] = Field(default=None, alias="BatchErrors")
    operation_errors: Optional[List[Optional[OperationError]]] = Field(default=None, alias="OperationErrors")
    tracking_id: Optional[StrictStr] = Field(default=None, alias="TrackingId")
    type: Optional[StrictStr] = Field(default='EditorialApiFaultDetail', alias="Type")
    __properties: ClassVar[List[str]] = ["EditorialErrors", "BatchErrors", "OperationErrors", "TrackingId", "Type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )
	
    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 EditorialApiFaultDetail 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 editorial_errors (list)
        _items = []
        if self.editorial_errors:
            for _item_editorial_errors in self.editorial_errors:
                if _item_editorial_errors:
                    _items.append(_item_editorial_errors.to_dict())
            _dict['EditorialErrors'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in batch_errors (list)
        _items = []
        if self.batch_errors:
            for _item_batch_errors in self.batch_errors:
                if _item_batch_errors:
                    _items.append(_item_batch_errors.to_dict())
            _dict['BatchErrors'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in operation_errors (list)
        _items = []
        if self.operation_errors:
            for _item_operation_errors in self.operation_errors:
                if _item_operation_errors:
                    _items.append(_item_operation_errors.to_dict())
            _dict['OperationErrors'] = _items
        # set to None if editorial_errors (nullable) is None
        # and model_fields_set contains the field
        if self.editorial_errors is None and "editorial_errors" in self.model_fields_set:
            _dict['EditorialErrors'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "EditorialErrors": [EditorialError.from_dict(_item) for _item in obj["EditorialErrors"]] if obj.get("EditorialErrors") is not None else None,
                        "BatchErrors": [BatchError.from_dict(_item) for _item in obj["BatchErrors"]] if obj.get("BatchErrors") is not None else None,
                        "OperationErrors": [OperationError.from_dict(_item) for _item in obj["OperationErrors"]] if obj.get("OperationErrors") is not None else None,
                        "TrackingId": obj.get("TrackingId") if obj.get("TrackingId") is not None else None,
                        "Type": obj.get("Type") if obj.get("Type") is not None else 'EditorialApiFaultDetail'
        })
        return _obj
