# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from artifact_keeper_client.models.format_handler_type import FormatHandlerType
from typing import Optional, Set
from typing_extensions import Self

class FormatHandlerResponse(BaseModel):
    """
    Format handler response with additional computed fields.
    """ # noqa: E501
    capabilities: Optional[Dict[str, Any]] = Field(default=None, description="Plugin capabilities if this is a WASM handler")
    created_at: datetime
    description: Optional[StrictStr] = None
    display_name: StrictStr
    extensions: List[StrictStr]
    format_key: StrictStr
    handler_type: FormatHandlerType
    id: StrictStr
    is_enabled: StrictBool
    plugin_id: Optional[StrictStr] = None
    priority: StrictInt
    repository_count: Optional[StrictInt] = Field(default=None, description="Number of repositories using this format (computed)")
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["capabilities", "created_at", "description", "display_name", "extensions", "format_key", "handler_type", "id", "is_enabled", "plugin_id", "priority", "repository_count", "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 FormatHandlerResponse 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,
        )
        # set to None if capabilities (nullable) is None
        # and model_fields_set contains the field
        if self.capabilities is None and "capabilities" in self.model_fields_set:
            _dict['capabilities'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "capabilities": obj.get("capabilities"),
            "created_at": obj.get("created_at"),
            "description": obj.get("description"),
            "display_name": obj.get("display_name"),
            "extensions": obj.get("extensions"),
            "format_key": obj.get("format_key"),
            "handler_type": obj.get("handler_type"),
            "id": obj.get("id"),
            "is_enabled": obj.get("is_enabled"),
            "plugin_id": obj.get("plugin_id"),
            "priority": obj.get("priority"),
            "repository_count": obj.get("repository_count"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


