# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.display_config_input import DisplayConfigInput
from mixpeek.models.rate_limit_config import RateLimitConfig
from typing import Optional, Set
from typing_extensions import Self

class PublishRetrieverRequest(BaseModel):
    """
    Request to publish a retriever.  Requires public_name. display_config is optional - if not provided, the retriever's stored display_config will be used (if available).
    """ # noqa: E501
    public_name: Annotated[str, Field(min_length=3, strict=True, max_length=50)] = Field(description="Public URL-safe name (lowercase, numbers, hyphens only). Must start and end with alphanumeric character. Will be used in URL: apps.mixpeek.com/r/{public_name}")
    description: Optional[Annotated[str, Field(strict=True, max_length=500)]] = Field(default=None, description="Description of this public retriever. Explains what the retriever does and what it searches. Displayed in public listings and search results.")
    icon_base64: Optional[Annotated[str, Field(strict=True, max_length=300000)]] = Field(default=None, description="Base64 encoded icon/favicon for this public retriever. Data URI format recommended. Max size: ~200KB encoded. Displayed in public listings and as the retriever's icon.")
    display_config: Optional[DisplayConfigInput] = Field(default=None, description="Display configuration defining how the public UI should be rendered. Includes input fields, theme, layout, and exposed result fields. If not provided, uses the retriever's stored display_config.")
    rate_limit_config: Optional[RateLimitConfig] = Field(default=None, description="Rate limiting configuration for public endpoint. Defaults to STANDARD tier (10/min, 100/hour, 1k/day). Use ELEVATED tier for trusted public apps (30/min, 500/hour, 5k/day). Use ENTERPRISE tier for monitored deployments (100/min, 2k/hour, 20k/day). Custom limits override tier defaults.")
    password_secret_name: Optional[StrictStr] = Field(default=None, description="OPTIONAL. Name of organization secret containing password for access protection. If provided, users must send password via X-Retriever-Password header.")
    include_metadata: Optional[StrictBool] = Field(default=True, description="Whether to capture and store retriever metadata (stages, collections, capabilities). Recommended: True for better developer experience and debugging. Default: True.")
    __properties: ClassVar[List[str]] = ["public_name", "description", "icon_base64", "display_config", "rate_limit_config", "password_secret_name", "include_metadata"]

    @field_validator('public_name')
    def public_name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-z0-9][a-z0-9-]*[a-z0-9]$", value):
            raise ValueError(r"must validate the regular expression /^[a-z0-9][a-z0-9-]*[a-z0-9]$/")
        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 PublishRetrieverRequest 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 display_config
        if self.display_config:
            _dict['display_config'] = self.display_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of rate_limit_config
        if self.rate_limit_config:
            _dict['rate_limit_config'] = self.rate_limit_config.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "public_name": obj.get("public_name"),
            "description": obj.get("description"),
            "icon_base64": obj.get("icon_base64"),
            "display_config": DisplayConfigInput.from_dict(obj["display_config"]) if obj.get("display_config") is not None else None,
            "rate_limit_config": RateLimitConfig.from_dict(obj["rate_limit_config"]) if obj.get("rate_limit_config") is not None else None,
            "password_secret_name": obj.get("password_secret_name"),
            "include_metadata": obj.get("include_metadata") if obj.get("include_metadata") is not None else True
        })
        return _obj


