# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.api_plugins_models_plugin_manifest_metadata import ApiPluginsModelsPluginManifestMetadata
from mixpeek.models.plugin_deployment_info import PluginDeploymentInfo
from typing import Optional, Set
from typing_extensions import Self

class ApiPluginsModelsPluginDocument(BaseModel):
    """
    Plugin document stored in MongoDB.  Org-scoped: Uses organization_id instead of namespace_id. Plugins belong to an organization and can be used by any namespace within that org.
    """ # noqa: E501
    plugin_id: StrictStr = Field(description="Unique plugin identifier")
    organization_id: StrictStr = Field(description="Owner organization ID")
    name: StrictStr = Field(description="Plugin name")
    version: StrictStr = Field(description="Plugin version (semver)")
    description: Optional[StrictStr] = Field(default=None, description="Plugin description")
    s3_archive_url: StrictStr = Field(description="S3 URL to plugin archive")
    code_hash: StrictStr = Field(description="SHA256 hash of plugin code")
    validation_status: StrictStr = Field(description="Validation status")
    validation_errors: Optional[List[StrictStr]] = Field(default=None, description="Validation error messages")
    security_scan_passed: Optional[StrictBool] = Field(default=False, description="Whether security scan passed")
    deployed: Optional[StrictBool] = Field(default=False, description="Whether plugin is deployed")
    deployment_info: Optional[PluginDeploymentInfo] = Field(default=None, description="Deployment details")
    manifest: Optional[ApiPluginsModelsPluginManifestMetadata] = Field(default=None, description="Metadata extracted from manifest.py")
    created_at: Optional[datetime] = Field(default=None, description="Creation timestamp")
    updated_at: Optional[datetime] = Field(default=None, description="Last update timestamp")
    deployed_at: Optional[datetime] = Field(default=None, description="When plugin was last deployed")
    resolved_inference_name: Optional[StrictStr] = Field(default=None, description="Resolved inference service name (from realtime.py or feature_uri)")
    __properties: ClassVar[List[str]] = ["plugin_id", "organization_id", "name", "version", "description", "s3_archive_url", "code_hash", "validation_status", "validation_errors", "security_scan_passed", "deployed", "deployment_info", "manifest", "created_at", "updated_at", "deployed_at", "resolved_inference_name"]

    @field_validator('validation_status')
    def validation_status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['passed', 'failed', 'pending']):
            raise ValueError("must be one of enum values ('passed', 'failed', 'pending')")
        return value

    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 ApiPluginsModelsPluginDocument 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 deployment_info
        if self.deployment_info:
            _dict['deployment_info'] = self.deployment_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of manifest
        if self.manifest:
            _dict['manifest'] = self.manifest.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "plugin_id": obj.get("plugin_id"),
            "organization_id": obj.get("organization_id"),
            "name": obj.get("name"),
            "version": obj.get("version"),
            "description": obj.get("description"),
            "s3_archive_url": obj.get("s3_archive_url"),
            "code_hash": obj.get("code_hash"),
            "validation_status": obj.get("validation_status"),
            "validation_errors": obj.get("validation_errors"),
            "security_scan_passed": obj.get("security_scan_passed") if obj.get("security_scan_passed") is not None else False,
            "deployed": obj.get("deployed") if obj.get("deployed") is not None else False,
            "deployment_info": PluginDeploymentInfo.from_dict(obj["deployment_info"]) if obj.get("deployment_info") is not None else None,
            "manifest": ApiPluginsModelsPluginManifestMetadata.from_dict(obj["manifest"]) if obj.get("manifest") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "deployed_at": obj.get("deployed_at"),
            "resolved_inference_name": obj.get("resolved_inference_name")
        })
        return _obj


