# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class ClickResource(BaseModel):
    """
    ClickResource
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="click unique uuid")
    browser_language: Optional[StrictStr] = Field(default=None, description="Language of user browser")
    country_code: Optional[StrictStr] = Field(default=None, description="User country detected by geo ip")
    is_human: Optional[StrictBool] = Field(default=None, description="We use some heuristics to determine is it real human or looks like bot")
    is_unique: Optional[StrictBool] = Field(default=None, description="We use combination of ip address user-agent cookies and so on to account the same user just once")
    http_status: Optional[StrictInt] = Field(default=None, description="Status code returned by GET original link when redirecting the user")
    http_method: Optional[StrictStr] = Field(default=None, description="Http method used by user when click on short link")
    created_at: Optional[datetime] = Field(default=None, description="Date and time of click")
    user_agent: Optional[StrictStr] = Field(default=None, description="User-agent of first click")
    client_ip: Optional[StrictStr] = Field(default=None, description="Client IP address of first click")
    browser: Optional[StrictStr] = Field(default=None, description="User browser detected from user-agent")
    referrer_url: Optional[StrictStr] = Field(default=None, description="source page from witch user click on short link")
    city: Optional[StrictStr] = Field(default=None, description="User city detected by geo ip")
    device_os: Optional[StrictStr] = Field(default=None, description="User device operation system detected from user-agent")
    short_link: Optional[StrictStr] = Field(default=None, description="short link url that can be used to redirect to original link")
    original_link: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=2048)]] = Field(default=None, description="Original link where to short link will redirect")
    message_id: Optional[StrictInt] = Field(default=None, description="message id for short links created as part of [sms campaign](#tag/Campaign-SMS)")
    phone_number: Optional[StrictInt] = Field(default=None, description="Phone number without leading plus. For short links created as part of [sms campaign](#tag/Campaign-SMS)")
    __properties: ClassVar[List[str]] = ["id", "browser_language", "country_code", "is_human", "is_unique", "http_status", "http_method", "created_at", "user_agent", "client_ip", "browser", "referrer_url", "city", "device_os", "short_link", "original_link", "message_id", "phone_number"]

    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 ClickResource 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,
        )
        # set to None if country_code (nullable) is None
        # and model_fields_set contains the field
        if self.country_code is None and "country_code" in self.model_fields_set:
            _dict['country_code'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ClickResource 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"),
            "browser_language": obj.get("browser_language"),
            "country_code": obj.get("country_code"),
            "is_human": obj.get("is_human"),
            "is_unique": obj.get("is_unique"),
            "http_status": obj.get("http_status"),
            "http_method": obj.get("http_method"),
            "created_at": obj.get("created_at"),
            "user_agent": obj.get("user_agent"),
            "client_ip": obj.get("client_ip"),
            "browser": obj.get("browser"),
            "referrer_url": obj.get("referrer_url"),
            "city": obj.get("city"),
            "device_os": obj.get("device_os"),
            "short_link": obj.get("short_link"),
            "original_link": obj.get("original_link"),
            "message_id": obj.get("message_id"),
            "phone_number": obj.get("phone_number")
        })
        return _obj


