# coding: utf-8

"""
    One-API

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

    The version of the OpenAPI document: 2.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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from bsg_api.models.contact_group_schema import ContactGroupSchema
from typing import Optional, Set
from typing_extensions import Self

class ContactSchema(BaseModel):
    """
    Contact data
    """ # noqa: E501
    id: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="Contact ID in the platform personal account, which is generated automatically when a contact is added to the Contact Book")
    phone: Optional[Annotated[int, Field(le=999999999999999, strict=True, ge=100000000)]] = Field(default=None, description="Contact’s phone number")
    fields: Optional[List[Dict[str, StrictStr]]] = Field(default=None, description="List of contact custom field values")
    created_at: Optional[datetime] = Field(default=None, description="Date when the item was created in the system ― set by the system automatically. Display format ― Y-m-d H:i:s")
    groups: Optional[Annotated[List[ContactGroupSchema], Field(max_length=100)]] = Field(default=None, description="contains embedded data of the list where the contact is added")
    hlr_status: Optional[StrictStr] = Field(default=None, description="Last hlr check status of contact phone number")
    hlr_last_check: Optional[datetime] = Field(default=None, description="Last hlr check time of contact phone number")
    __properties: ClassVar[List[str]] = ["id", "phone", "fields", "created_at", "groups", "hlr_status", "hlr_last_check"]

    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 ContactSchema 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 groups (list)
        _items = []
        if self.groups:
            for _item_groups in self.groups:
                if _item_groups:
                    _items.append(_item_groups.to_dict())
            _dict['groups'] = _items
        # set to None if hlr_last_check (nullable) is None
        # and model_fields_set contains the field
        if self.hlr_last_check is None and "hlr_last_check" in self.model_fields_set:
            _dict['hlr_last_check'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "phone": obj.get("phone"),
            "fields": obj.get("fields"),
            "created_at": obj.get("created_at"),
            "groups": [ContactGroupSchema.from_dict(_item) for _item in obj["groups"]] if obj.get("groups") is not None else None,
            "hlr_status": obj.get("hlr_status"),
            "hlr_last_check": obj.get("hlr_last_check")
        })
        return _obj


