# coding: utf-8

"""
    Guardrails Hub Types

    Data structures used in the Guardrails Hub

    The version of the OpenAPI document: 0.0.0
    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
from typing import Any, ClassVar, Dict, List, Optional
from guardrails_hub_types.models.contributor import Contributor
from guardrails_hub_types.models.manifest_parameters import ManifestParameters
from guardrails_hub_types.models.model_auth import ModelAuth
from guardrails_hub_types.models.repository import Repository
from guardrails_hub_types.models.tags import Tags
from typing import Set
from typing_extensions import Self

class Manifest(BaseModel):
    """
    Manifest
    """ # noqa: E501
    id: StrictStr = Field(description="The namespaced identifier with which the validator registers.")
    name: StrictStr = Field(description="The Title Cased human-readable name for the validator.")
    description: StrictStr = Field(description="A description that concisely states the expected behaviour of the validator.")
    author: Contributor = Field(description="The primary contact for the validator's git repository.")
    maintainers: List[Contributor] = Field(description="A list of all contacs for the validator's git repository.")
    repository: Repository = Field(description="The git repository that contains the source code for this validator.")
    namespace: StrictStr = Field(description="The organizational namespace for this validator; the prefix of the id.")
    package_name: StrictStr = Field(description="The python package name for this validator; typically the same as the repository name and the suffix of the id.", alias="packageName")
    module_name: StrictStr = Field(description="The python module name for this validator; typically \"validator\"", alias="moduleName")
    exports: List[StrictStr] = Field(description="The exports from the validator module; typically at least the validator's class name.")
    tags: Optional[Tags] = None
    requires_auth: Optional[StrictBool] = Field(default=True, description="Indicates whether the user must be authenticated to install this validator.", alias="requiresAuth")
    post_install: Optional[StrictStr] = Field(default='post-install.py', description="The file path, relative to the module directory, to the post-install script for this validator.", alias="postInstall")
    index: Optional[StrictStr] = Field(default='__init__.py', description="The file path, relative to the module directory, to the index file for this validator.")
    featured: Optional[StrictBool] = Field(default=False, description="Indicates whether this validator is currently featured.")
    playground_enabled: Optional[StrictBool] = Field(default=False, description="Indicates whether this validator can be used in the Guardrails Hub Playground.", alias="playgroundEnabled")
    parameters: Optional[ManifestParameters] = None
    metadata: Optional[Dict[str, Any]] = None
    required_model_auth: Optional[List[ModelAuth]] = Field(default=None, alias="requiredModelAuth")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "author", "maintainers", "repository", "namespace", "packageName", "moduleName", "exports", "tags", "requiresAuth", "postInstall", "index", "featured", "playgroundEnabled", "parameters", "metadata", "requiredModelAuth"]

    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 Manifest 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 author
        if self.author:
            _dict['author'] = self.author.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in maintainers (list)
        _items = []
        if self.maintainers:
            for _item in self.maintainers:
                if _item:
                    _items.append(_item.to_dict())
            _dict['maintainers'] = _items
        # override the default output from pydantic by calling `to_dict()` of repository
        if self.repository:
            _dict['repository'] = self.repository.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tags
        if self.tags:
            _dict['tags'] = self.tags.to_dict()
        # override the default output from pydantic by calling `to_dict()` of parameters
        if self.parameters:
            _dict['parameters'] = self.parameters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in required_model_auth (list)
        _items = []
        if self.required_model_auth:
            for _item in self.required_model_auth:
                if _item:
                    _items.append(_item.to_dict())
            _dict['requiredModelAuth'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Manifest 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"),
            "description": obj.get("description"),
            "author": Contributor.from_dict(obj["author"]) if obj.get("author") is not None else None,
            "maintainers": [Contributor.from_dict(_item) for _item in obj["maintainers"]] if obj.get("maintainers") is not None else None,
            "repository": Repository.from_dict(obj["repository"]) if obj.get("repository") is not None else None,
            "namespace": obj.get("namespace"),
            "packageName": obj.get("packageName"),
            "moduleName": obj.get("moduleName"),
            "exports": obj.get("exports"),
            "tags": Tags.from_dict(obj["tags"]) if obj.get("tags") is not None else None,
            "requiresAuth": obj.get("requiresAuth") if obj.get("requiresAuth") is not None else True,
            "postInstall": obj.get("postInstall") if obj.get("postInstall") is not None else 'post-install.py',
            "index": obj.get("index") if obj.get("index") is not None else '__init__.py',
            "featured": obj.get("featured") if obj.get("featured") is not None else False,
            "playgroundEnabled": obj.get("playgroundEnabled") if obj.get("playgroundEnabled") is not None else False,
            "parameters": ManifestParameters.from_dict(obj["parameters"]) if obj.get("parameters") is not None else None,
            "metadata": obj.get("metadata"),
            "requiredModelAuth": [ModelAuth.from_dict(_item) for _item in obj["requiredModelAuth"]] if obj.get("requiredModelAuth") is not None else None
        })
        return _obj


