# coding: utf-8

"""
    URLR API Reference

    API powering the features of URLR.<br><br>Note that in order to facilitate integration, we provide SDKs for various languages at https://github.com/URLR.<br><br>Key API principles:<br>         <ul><li>All dates follow **ISO-8601** format</li><li>Most errors follow **RFC 9457** standard</li><li>All responses are delivered in English</li></ul>

    The version of the OpenAPI document: 1.3
    Contact: contact@urlr.me
    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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from urlr.models.create_link_request_metatag import CreateLinkRequestMetatag
from urlr.models.create_link_request_qrcode import CreateLinkRequestQrcode
from typing import Optional, Set
from typing_extensions import Self

class CreateLinkRequest(BaseModel):
    """
    CreateLinkRequest
    """ # noqa: E501
    url: StrictStr = Field(description="URL to shorten")
    team_id: StrictStr = Field(description="Team API ID")
    folder_id: Optional[StrictStr] = Field(default=None, description="Folder API ID")
    domain: Optional[StrictStr] = Field(default=None, description="Domain")
    code: Optional[Annotated[str, Field(strict=True)]] = Field(default=None, description="Custom short code")
    label: Optional[StrictStr] = Field(default=None, description="Label")
    password: Optional[StrictStr] = Field(default=None, description="Password")
    qrcode: Optional[CreateLinkRequestQrcode] = None
    metatag: Optional[CreateLinkRequestMetatag] = None
    expired_at: Optional[datetime] = Field(default=None, description="Expiration date")
    expired_url: Optional[StrictStr] = Field(default=None, description="Expiration URL")
    __properties: ClassVar[List[str]] = ["url", "team_id", "folder_id", "domain", "code", "label", "password", "qrcode", "metatag", "expired_at", "expired_url"]

    @field_validator('code')
    def code_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[a-zA-Z0-9!-]{3,50}$", value):
            raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9!-]{3,50}$/")
        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 CreateLinkRequest 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 qrcode
        if self.qrcode:
            _dict['qrcode'] = self.qrcode.to_dict()
        # override the default output from pydantic by calling `to_dict()` of metatag
        if self.metatag:
            _dict['metatag'] = self.metatag.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "url": obj.get("url"),
            "team_id": obj.get("team_id"),
            "folder_id": obj.get("folder_id"),
            "domain": obj.get("domain"),
            "code": obj.get("code"),
            "label": obj.get("label"),
            "password": obj.get("password"),
            "qrcode": CreateLinkRequestQrcode.from_dict(obj["qrcode"]) if obj.get("qrcode") is not None else None,
            "metatag": CreateLinkRequestMetatag.from_dict(obj["metatag"]) if obj.get("metatag") is not None else None,
            "expired_at": obj.get("expired_at"),
            "expired_url": obj.get("expired_url")
        })
        return _obj


