# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from gmail_ti.models.label_color import LabelColor
from typing import Optional, Set
from typing_extensions import Self

class Label(BaseModel):
    """
    Labels are used to categorize messages and threads within the user's mailbox.
    """ # noqa: E501
    color: Optional[LabelColor] = None
    id: Optional[StrictStr] = Field(default=None, description="The immutable ID of the label.")
    label_list_visibility: Optional[StrictStr] = Field(default=None, description="The visibility of the label in the label list in the Gmail web interface.", alias="labelListVisibility")
    message_list_visibility: Optional[StrictStr] = Field(default=None, description="The visibility of messages with this label in the message list in the Gmail web interface.", alias="messageListVisibility")
    messages_total: Optional[StrictInt] = Field(default=None, description="The total number of messages with the label.", alias="messagesTotal")
    messages_unread: Optional[StrictInt] = Field(default=None, description="The number of unread messages with the label.", alias="messagesUnread")
    name: Optional[StrictStr] = Field(default=None, description="The display name of the label.")
    threads_total: Optional[StrictInt] = Field(default=None, description="The total number of threads with the label.", alias="threadsTotal")
    threads_unread: Optional[StrictInt] = Field(default=None, description="The number of unread threads with the label.", alias="threadsUnread")
    type: Optional[StrictStr] = Field(default=None, description="The owner type for the label. User labels are created by the user and can be modified and deleted by the user and can be applied to any message or thread. System labels are internally created and cannot be added, modified, or deleted. System labels may be able to be applied to or removed from messages and threads under some circumstances but this is not guaranteed. For example, users can apply and remove the `INBOX` and `UNREAD` labels from messages and threads, but cannot apply or remove the `DRAFTS` or `SENT` labels from messages or threads.")
    __properties: ClassVar[List[str]] = ["color", "id", "labelListVisibility", "messageListVisibility", "messagesTotal", "messagesUnread", "name", "threadsTotal", "threadsUnread", "type"]

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

        if value not in set(['labelShow', 'labelShowIfUnread', 'labelHide']):
            raise ValueError("must be one of enum values ('labelShow', 'labelShowIfUnread', 'labelHide')")
        return value

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

        if value not in set(['show', 'hide']):
            raise ValueError("must be one of enum values ('show', 'hide')")
        return value

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

        if value not in set(['system', 'user']):
            raise ValueError("must be one of enum values ('system', 'user')")
        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 Label 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 color
        if self.color:
            _dict['color'] = self.color.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "color": LabelColor.from_dict(obj["color"]) if obj.get("color") is not None else None,
            "id": obj.get("id"),
            "labelListVisibility": obj.get("labelListVisibility"),
            "messageListVisibility": obj.get("messageListVisibility"),
            "messagesTotal": obj.get("messagesTotal"),
            "messagesUnread": obj.get("messagesUnread"),
            "name": obj.get("name"),
            "threadsTotal": obj.get("threadsTotal"),
            "threadsUnread": obj.get("threadsUnread"),
            "type": obj.get("type")
        })
        return _obj


