# 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 datetime import datetime
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.otel_config import OtelConfig
from pydantic import TypeAdapter
from typing import Optional, Set
from typing_extensions import Self

_JSON_ADAPTER = TypeAdapter(Dict[str, Any])

class Organization(BaseModel):
    """
    Organization
    """ # noqa: E501
    id: StrictStr = Field(description="Organization ID")
    name: StrictStr = Field(description="Organization name")
    created_by: StrictStr = Field(description="User ID of the organization creator", serialization_alias="createdBy")
    personal: StrictBool = Field(description="Personal organization flag")
    created_at: datetime = Field(description="Creation timestamp", serialization_alias="createdAt")
    updated_at: datetime = Field(description="Last update timestamp", serialization_alias="updatedAt")
    suspended: StrictBool = Field(description="Suspended flag")
    suspended_at: datetime = Field(description="Suspended at", serialization_alias="suspendedAt")
    suspension_reason: StrictStr = Field(description="Suspended reason", serialization_alias="suspensionReason")
    suspended_until: datetime = Field(description="Suspended until", serialization_alias="suspendedUntil")
    suspension_cleanup_grace_period_hours: Union[StrictFloat, StrictInt] = Field(description="Suspension cleanup grace period hours", serialization_alias="suspensionCleanupGracePeriodHours")
    max_cpu_per_sandbox: Union[StrictFloat, StrictInt] = Field(description="Max CPU per sandbox", serialization_alias="maxCpuPerSandbox")
    max_memory_per_sandbox: Union[StrictFloat, StrictInt] = Field(description="Max memory per sandbox", serialization_alias="maxMemoryPerSandbox")
    max_disk_per_sandbox: Union[StrictFloat, StrictInt] = Field(description="Max disk per sandbox", serialization_alias="maxDiskPerSandbox")
    snapshot_deactivation_timeout_minutes: Union[StrictFloat, StrictInt] = Field(description="Time in minutes before an unused snapshot is deactivated", serialization_alias="snapshotDeactivationTimeoutMinutes")
    sandbox_limited_network_egress: StrictBool = Field(description="Sandbox default network block all", serialization_alias="sandboxLimitedNetworkEgress")
    default_region_id: Optional[StrictStr] = Field(default=None, description="Default region ID", serialization_alias="defaultRegionId")
    authenticated_rate_limit: Optional[Union[StrictFloat, StrictInt]] = Field(description="Authenticated rate limit per minute", serialization_alias="authenticatedRateLimit")
    sandbox_create_rate_limit: Optional[Union[StrictFloat, StrictInt]] = Field(description="Sandbox create rate limit per minute", serialization_alias="sandboxCreateRateLimit")
    sandbox_lifecycle_rate_limit: Optional[Union[StrictFloat, StrictInt]] = Field(description="Sandbox lifecycle rate limit per minute", serialization_alias="sandboxLifecycleRateLimit")
    experimental_config: Dict[str, Any] = Field(description="Experimental configuration", serialization_alias="experimentalConfig")
    otel_config: Optional[OtelConfig] = Field(description="OpenTelemetry collection configuration", serialization_alias="otelConfig")
    authenticated_rate_limit_ttl_seconds: Optional[Union[StrictFloat, StrictInt]] = Field(description="Authenticated rate limit TTL in seconds", serialization_alias="authenticatedRateLimitTtlSeconds")
    sandbox_create_rate_limit_ttl_seconds: Optional[Union[StrictFloat, StrictInt]] = Field(description="Sandbox create rate limit TTL in seconds", serialization_alias="sandboxCreateRateLimitTtlSeconds")
    sandbox_lifecycle_rate_limit_ttl_seconds: Optional[Union[StrictFloat, StrictInt]] = Field(description="Sandbox lifecycle rate limit TTL in seconds", serialization_alias="sandboxLifecycleRateLimitTtlSeconds")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["id", "name", "createdBy", "personal", "createdAt", "updatedAt", "suspended", "suspendedAt", "suspensionReason", "suspendedUntil", "suspensionCleanupGracePeriodHours", "maxCpuPerSandbox", "maxMemoryPerSandbox", "maxDiskPerSandbox", "snapshotDeactivationTimeoutMinutes", "sandboxLimitedNetworkEgress", "defaultRegionId", "authenticatedRateLimit", "sandboxCreateRateLimit", "sandboxLifecycleRateLimit", "experimentalConfig", "otelConfig", "authenticatedRateLimitTtlSeconds", "sandboxCreateRateLimitTtlSeconds", "sandboxLifecycleRateLimitTtlSeconds"]

    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 Organization 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 otel_config
        if self.otel_config:
            _dict['otelConfig'] = self.otel_config.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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Organization 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"),
            "name": obj.get("name"),
            "created_by": obj.get("createdBy"),
            "personal": obj.get("personal"),
            "created_at": obj.get("createdAt"),
            "updated_at": obj.get("updatedAt"),
            "suspended": obj.get("suspended"),
            "suspended_at": obj.get("suspendedAt"),
            "suspension_reason": obj.get("suspensionReason"),
            "suspended_until": obj.get("suspendedUntil"),
            "suspension_cleanup_grace_period_hours": obj.get("suspensionCleanupGracePeriodHours"),
            "max_cpu_per_sandbox": obj.get("maxCpuPerSandbox"),
            "max_memory_per_sandbox": obj.get("maxMemoryPerSandbox"),
            "max_disk_per_sandbox": obj.get("maxDiskPerSandbox"),
            "snapshot_deactivation_timeout_minutes": obj.get("snapshotDeactivationTimeoutMinutes") if obj.get("snapshotDeactivationTimeoutMinutes") is not None else 20160,
            "sandbox_limited_network_egress": obj.get("sandboxLimitedNetworkEgress"),
            "default_region_id": obj.get("defaultRegionId"),
            "authenticated_rate_limit": obj.get("authenticatedRateLimit"),
            "sandbox_create_rate_limit": obj.get("sandboxCreateRateLimit"),
            "sandbox_lifecycle_rate_limit": obj.get("sandboxLifecycleRateLimit"),
            "experimental_config": obj.get("experimentalConfig"),
            "otel_config": OtelConfig.from_dict(obj["otelConfig"]) if obj.get("otelConfig") is not None else None,
            "authenticated_rate_limit_ttl_seconds": obj.get("authenticatedRateLimitTtlSeconds"),
            "sandbox_create_rate_limit_ttl_seconds": obj.get("sandboxCreateRateLimitTtlSeconds"),
            "sandbox_lifecycle_rate_limit_ttl_seconds": obj.get("sandboxLifecycleRateLimitTtlSeconds")
        })
        # 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


