# coding: utf-8

"""
    Onboarding Buddy API

    This document details all the available operations in the Onboarding Buddy API specification

    The version of the OpenAPI document: v1
    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
from typing import Any, ClassVar, Dict, List, Optional
from onboarding_buddy_client.models.email_individual_record_m import EmailIndividualRecordM
from onboarding_buddy_client.models.individual_alias_m import IndividualAliasM
from typing import Optional, Set
from typing_extensions import Self

class EmailEntityRecordM(BaseModel):
    """
    EmailEntityRecordM
    """ # noqa: E501
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    program: Optional[StrictStr] = None
    additional_info: Optional[List[StrictStr]] = Field(default=None, alias="additionalInfo")
    alias_list: Optional[List[IndividualAliasM]] = Field(default=None, alias="aliasList")
    linked_to: Optional[StrictStr] = Field(default=None, alias="linkedTo")
    secondary_sanctions_risk: Optional[StrictStr] = Field(default=None, alias="secondarySanctionsRisk")
    websites: Optional[List[StrictStr]] = None
    email_address: Optional[List[StrictStr]] = Field(default=None, alias="emailAddress")
    also_known_as: Optional[List[StrictStr]] = Field(default=None, alias="alsoKnownAs")
    linked_individuals: Optional[List[EmailIndividualRecordM]] = Field(default=None, alias="linkedIndividuals")
    linked_entity: Optional[List[EmailEntityRecordM]] = Field(default=None, alias="linkedEntity")
    __properties: ClassVar[List[str]] = ["fullName", "program", "additionalInfo", "aliasList", "linkedTo", "secondarySanctionsRisk", "websites", "emailAddress", "alsoKnownAs", "linkedIndividuals", "linkedEntity"]

    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 EmailEntityRecordM 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 alias_list (list)
        _items = []
        if self.alias_list:
            for _item_alias_list in self.alias_list:
                if _item_alias_list:
                    _items.append(_item_alias_list.to_dict())
            _dict['aliasList'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in linked_individuals (list)
        _items = []
        if self.linked_individuals:
            for _item_linked_individuals in self.linked_individuals:
                if _item_linked_individuals:
                    _items.append(_item_linked_individuals.to_dict())
            _dict['linkedIndividuals'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in linked_entity (list)
        _items = []
        if self.linked_entity:
            for _item_linked_entity in self.linked_entity:
                if _item_linked_entity:
                    _items.append(_item_linked_entity.to_dict())
            _dict['linkedEntity'] = _items
        # set to None if full_name (nullable) is None
        # and model_fields_set contains the field
        if self.full_name is None and "full_name" in self.model_fields_set:
            _dict['fullName'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "fullName": obj.get("fullName"),
            "program": obj.get("program"),
            "additionalInfo": obj.get("additionalInfo"),
            "aliasList": [IndividualAliasM.from_dict(_item) for _item in obj["aliasList"]] if obj.get("aliasList") is not None else None,
            "linkedTo": obj.get("linkedTo"),
            "secondarySanctionsRisk": obj.get("secondarySanctionsRisk"),
            "websites": obj.get("websites"),
            "emailAddress": obj.get("emailAddress"),
            "alsoKnownAs": obj.get("alsoKnownAs"),
            "linkedIndividuals": [EmailIndividualRecordM.from_dict(_item) for _item in obj["linkedIndividuals"]] if obj.get("linkedIndividuals") is not None else None,
            "linkedEntity": [EmailEntityRecordM.from_dict(_item) for _item in obj["linkedEntity"]] if obj.get("linkedEntity") is not None else None
        })
        return _obj

# TODO: Rewrite to not use raise_errors
EmailEntityRecordM.model_rebuild(raise_errors=False)

