# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from iblai.models.claw_instance_status_enum import ClawInstanceStatusEnum
from iblai.models.claw_type_enum import ClawTypeEnum
from iblai.models.deploy_state_enum import DeployStateEnum
from iblai.models.provision_mode_enum import ProvisionModeEnum
from typing import Optional, Set
from typing_extensions import Self

class PatchedClawInstance(BaseModel):
    """
    PatchedClawInstance
    """ # noqa: E501
    id: Optional[StrictInt] = None
    name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    claw_type: Optional[ClawTypeEnum] = None
    provision_mode: Optional[ProvisionModeEnum] = Field(default=None, description="Managed = provisioned by us. Self-hosted = tenant provides the server.  * `managed` - Managed * `self_hosted` - Self-hosted")
    server_url: Optional[Annotated[str, Field(strict=True, max_length=200)]] = Field(default=None, description="HTTPS URL of the Claw worker instance.")
    gateway_token: Optional[StrictStr] = None
    deployment_backend: Optional[StrictInt] = Field(default=None, description="Backend that deployed this server. Null = manually configured.")
    auth_headers: Optional[Any] = Field(default=None, description="Per-server auth headers (overrides backend defaults).")
    connection_params: Optional[Any] = Field(default=None, description="Variant-specific connection parameters (write-only in API). OpenClaw: device_identity.private_key_pem, timeouts. IronClaw: typically empty (bearer token covered by gateway_token).")
    status: Optional[ClawInstanceStatusEnum] = None
    deploy_state: Optional[DeployStateEnum] = None
    platform_key: Optional[StrictStr] = None
    last_health_check: Optional[datetime] = None
    last_health_status: Optional[StrictStr] = None
    claw_version: Optional[StrictStr] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    __properties: ClassVar[List[str]] = ["id", "name", "claw_type", "provision_mode", "server_url", "gateway_token", "deployment_backend", "auth_headers", "connection_params", "status", "deploy_state", "platform_key", "last_health_check", "last_health_status", "claw_version", "created_at", "updated_at"]

    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 PatchedClawInstance 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "provision_mode",
            "status",
            "deploy_state",
            "platform_key",
            "last_health_check",
            "last_health_status",
            "claw_version",
            "created_at",
            "updated_at",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if deployment_backend (nullable) is None
        # and model_fields_set contains the field
        if self.deployment_backend is None and "deployment_backend" in self.model_fields_set:
            _dict['deployment_backend'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PatchedClawInstance 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"),
            "claw_type": obj.get("claw_type"),
            "provision_mode": obj.get("provision_mode"),
            "server_url": obj.get("server_url"),
            "gateway_token": obj.get("gateway_token"),
            "deployment_backend": obj.get("deployment_backend"),
            "auth_headers": obj.get("auth_headers"),
            "connection_params": obj.get("connection_params"),
            "status": obj.get("status"),
            "deploy_state": obj.get("deploy_state"),
            "platform_key": obj.get("platform_key"),
            "last_health_check": obj.get("last_health_check"),
            "last_health_status": obj.get("last_health_status"),
            "claw_version": obj.get("claw_version"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


