# 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 bsg_api.models.short_link_status import ShortLinkStatus
from typing import Optional, Set
from typing_extensions import Self

class ShortUrlLinkSchema(BaseModel):
    """
    Short Link object
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="short link unique id")
    status: Optional[ShortLinkStatus] = None
    name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=50)]] = Field(default=None, description="Name of short link. like a comment")
    slug: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=25)]] = Field(default=None, description="part of short link after domain")
    campaign_id: Optional[StrictInt] = Field(default=None, description="campaign ID if short link is part of sms campaign.  Campaign allow send messages to all the leads with different short link for each lead that follows to the same original link")
    message_id: Optional[StrictInt] = Field(default=None, description="message id for short links created as part of [sms campaign](#tag/Campaign-SMS)")
    init_deleted_at: Optional[datetime] = Field(default=None, description="Date and time when short link was deactivated")
    created_at: Optional[datetime] = Field(default=None, description="Date and time when short link was created")
    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")
    can_restore: Optional[StrictBool] = Field(default=True, description="For link marked as deleted it can be restored a few time if can_restore=true")
    count_clicks: Optional[StrictInt] = Field(default=None, description="Number of clicks on a short link  *Please note: count of clicks updated with some latency*")
    count_human_clicks: Optional[StrictInt] = Field(default=None, description="Number of clicks on a short link looks like human  We use some heuristics to determine is it real human or looks like bot")
    count_unique_clicks: Optional[StrictInt] = Field(default=None, description="Number of unique clicks on a short link  We use combination of ip address user-agent cookies and so on to account the same user just once")
    __properties: ClassVar[List[str]] = ["id", "status", "name", "slug", "campaign_id", "message_id", "init_deleted_at", "created_at", "short_link", "original_link", "can_restore", "count_clicks", "count_human_clicks", "count_unique_clicks"]

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ShortUrlLinkSchema 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"),
            "status": obj.get("status"),
            "name": obj.get("name"),
            "slug": obj.get("slug"),
            "campaign_id": obj.get("campaign_id"),
            "message_id": obj.get("message_id"),
            "init_deleted_at": obj.get("init_deleted_at"),
            "created_at": obj.get("created_at"),
            "short_link": obj.get("short_link"),
            "original_link": obj.get("original_link"),
            "can_restore": obj.get("can_restore") if obj.get("can_restore") is not None else True,
            "count_clicks": obj.get("count_clicks"),
            "count_human_clicks": obj.get("count_human_clicks"),
            "count_unique_clicks": obj.get("count_unique_clicks")
        })
        return _obj


