# coding: utf-8

"""
    Gmail API

    The Gmail API lets you view and manage Gmail mailbox data like threads, messages, and labels.

    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from gmail_ti.models.smtp_msa import SmtpMsa
from typing import Optional, Set
from typing_extensions import Self

class SendAs(BaseModel):
    """
    Settings associated with a send-as alias, which can be either the primary login address associated with the account or a custom \"from\" address. Send-as aliases correspond to the \"Send Mail As\" feature in the web interface.
    """ # noqa: E501
    display_name: Optional[StrictStr] = Field(default=None, description="A name that appears in the \"From:\" header for mail sent using this alias. For custom \"from\" addresses, when this is empty, Gmail will populate the \"From:\" header with the name that is used for the primary address associated with the account. If the admin has disabled the ability for users to update their name format, requests to update this field for the primary login will silently fail.", alias="displayName")
    is_default: Optional[StrictBool] = Field(default=None, description="Whether this address is selected as the default \"From:\" address in situations such as composing a new message or sending a vacation auto-reply. Every Gmail account has exactly one default send-as address, so the only legal value that clients may write to this field is `true`. Changing this from `false` to `true` for an address will result in this field becoming `false` for the other previous default address.", alias="isDefault")
    is_primary: Optional[StrictBool] = Field(default=None, description="Whether this address is the primary address used to login to the account. Every Gmail account has exactly one primary address, and it cannot be deleted from the collection of send-as aliases. This field is read-only.", alias="isPrimary")
    reply_to_address: Optional[StrictStr] = Field(default=None, description="An optional email address that is included in a \"Reply-To:\" header for mail sent using this alias. If this is empty, Gmail will not generate a \"Reply-To:\" header.", alias="replyToAddress")
    send_as_email: Optional[StrictStr] = Field(default=None, description="The email address that appears in the \"From:\" header for mail sent using this alias. This is read-only for all operations except create.", alias="sendAsEmail")
    signature: Optional[StrictStr] = Field(default=None, description="An optional HTML signature that is included in messages composed with this alias in the Gmail web UI.")
    smtp_msa: Optional[SmtpMsa] = Field(default=None, alias="smtpMsa")
    treat_as_alias: Optional[StrictBool] = Field(default=None, description="Whether Gmail should treat this address as an alias for the user's primary email address. This setting only applies to custom \"from\" aliases.", alias="treatAsAlias")
    verification_status: Optional[StrictStr] = Field(default=None, description="Indicates whether this address has been verified for use as a send-as alias. Read-only. This setting only applies to custom \"from\" aliases.", alias="verificationStatus")
    __properties: ClassVar[List[str]] = ["displayName", "isDefault", "isPrimary", "replyToAddress", "sendAsEmail", "signature", "smtpMsa", "treatAsAlias", "verificationStatus"]

    @field_validator('verification_status')
    def verification_status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['verificationStatusUnspecified', 'accepted', 'pending']):
            raise ValueError("must be one of enum values ('verificationStatusUnspecified', 'accepted', 'pending')")
        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 SendAs 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 smtp_msa
        if self.smtp_msa:
            _dict['smtpMsa'] = self.smtp_msa.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "displayName": obj.get("displayName"),
            "isDefault": obj.get("isDefault"),
            "isPrimary": obj.get("isPrimary"),
            "replyToAddress": obj.get("replyToAddress"),
            "sendAsEmail": obj.get("sendAsEmail"),
            "signature": obj.get("signature"),
            "smtpMsa": SmtpMsa.from_dict(obj["smtpMsa"]) if obj.get("smtpMsa") is not None else None,
            "treatAsAlias": obj.get("treatAsAlias"),
            "verificationStatus": obj.get("verificationStatus")
        })
        return _obj


