# coding: utf-8

"""
    Daytona

    Daytona AI platform API Docs

    The version of the OpenAPI document: 1.0
    Contact: support@daytona.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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from daytona_api_client_async.models.announcement import Announcement
from daytona_api_client_async.models.oidc_config import OidcConfig
from daytona_api_client_async.models.posthog_config import PosthogConfig
from daytona_api_client_async.models.rate_limit_config import RateLimitConfig
from pydantic import TypeAdapter
from typing import Optional, Set
from typing_extensions import Self

_JSON_ADAPTER = TypeAdapter(Dict[str, Any])

class DaytonaConfiguration(BaseModel):
    """
    DaytonaConfiguration
    """ # noqa: E501
    version: StrictStr = Field(description="Daytona version")
    posthog: Optional[PosthogConfig] = Field(default=None, description="PostHog configuration")
    oidc: OidcConfig = Field(description="OIDC configuration")
    linked_accounts_enabled: StrictBool = Field(description="Whether linked accounts are enabled", serialization_alias="linkedAccountsEnabled")
    announcements: Dict[str, Announcement] = Field(description="System announcements")
    pylon_app_id: Optional[StrictStr] = Field(default=None, description="Pylon application ID", serialization_alias="pylonAppId")
    proxy_template_url: StrictStr = Field(description="Proxy template URL", serialization_alias="proxyTemplateUrl")
    proxy_toolbox_url: StrictStr = Field(description="Toolbox template URL", serialization_alias="proxyToolboxUrl")
    default_snapshot: StrictStr = Field(description="Default snapshot for sandboxes", serialization_alias="defaultSnapshot")
    dashboard_url: StrictStr = Field(description="Dashboard URL", serialization_alias="dashboardUrl")
    max_auto_archive_interval: Union[StrictFloat, StrictInt] = Field(description="Maximum auto-archive interval in minutes", serialization_alias="maxAutoArchiveInterval")
    maintanance_mode: StrictBool = Field(description="Whether maintenance mode is enabled", serialization_alias="maintananceMode")
    environment: StrictStr = Field(description="Current environment")
    billing_api_url: Optional[StrictStr] = Field(default=None, description="Billing API URL", serialization_alias="billingApiUrl")
    analytics_api_url: Optional[StrictStr] = Field(default=None, description="Analytics API URL", serialization_alias="analyticsApiUrl")
    ssh_gateway_command: Optional[StrictStr] = Field(default=None, description="SSH Gateway command", serialization_alias="sshGatewayCommand")
    ssh_gateway_public_key: Optional[StrictStr] = Field(default=None, description="Base64 encoded SSH Gateway public key", serialization_alias="sshGatewayPublicKey")
    rate_limit: Optional[RateLimitConfig] = Field(default=None, description="Rate limit configuration", serialization_alias="rateLimit")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["version", "posthog", "oidc", "linkedAccountsEnabled", "announcements", "pylonAppId", "proxyTemplateUrl", "proxyToolboxUrl", "defaultSnapshot", "dashboardUrl", "maxAutoArchiveInterval", "maintananceMode", "environment", "billingApiUrl", "analyticsApiUrl", "sshGatewayCommand", "sshGatewayPublicKey", "rateLimit"]

    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"""
        return _JSON_ADAPTER.dump_json(self.to_dict()).decode()

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of DaytonaConfiguration 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of posthog
        if self.posthog:
            _dict['posthog'] = self.posthog.to_dict()
        # override the default output from pydantic by calling `to_dict()` of oidc
        if self.oidc:
            _dict['oidc'] = self.oidc.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in announcements (dict)
        _field_dict = {}
        if self.announcements:
            for _key_announcements in self.announcements:
                if self.announcements[_key_announcements]:
                    _field_dict[_key_announcements] = self.announcements[_key_announcements].to_dict()
            _dict['announcements'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of rate_limit
        if self.rate_limit:
            _dict['rateLimit'] = self.rate_limit.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "version": obj.get("version"),
            "posthog": PosthogConfig.from_dict(obj["posthog"]) if obj.get("posthog") is not None else None,
            "oidc": OidcConfig.from_dict(obj["oidc"]) if obj.get("oidc") is not None else None,
            "linked_accounts_enabled": obj.get("linkedAccountsEnabled"),
            "announcements": dict(
                (_k, Announcement.from_dict(_v))
                for _k, _v in obj["announcements"].items()
            )
            if obj.get("announcements") is not None
            else None,
            "pylon_app_id": obj.get("pylonAppId"),
            "proxy_template_url": obj.get("proxyTemplateUrl"),
            "proxy_toolbox_url": obj.get("proxyToolboxUrl"),
            "default_snapshot": obj.get("defaultSnapshot"),
            "dashboard_url": obj.get("dashboardUrl"),
            "max_auto_archive_interval": obj.get("maxAutoArchiveInterval"),
            "maintanance_mode": obj.get("maintananceMode"),
            "environment": obj.get("environment"),
            "billing_api_url": obj.get("billingApiUrl"),
            "analytics_api_url": obj.get("analyticsApiUrl"),
            "ssh_gateway_command": obj.get("sshGatewayCommand"),
            "ssh_gateway_public_key": obj.get("sshGatewayPublicKey"),
            "rate_limit": RateLimitConfig.from_dict(obj["rateLimit"]) if obj.get("rateLimit") is not None else None
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


