# coding: utf-8

"""
FastAPI

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 0.1.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, Dict, Optional

from truefoundry.ml.autogen.client.models.framework import Framework
from truefoundry.ml.autogen.client.models.model_version_environment import (
    ModelVersionEnvironment,
)
from truefoundry.ml.autogen.client.models.source1 import Source1
from truefoundry.pydantic_v1 import (
    BaseModel,
    Field,
    StrictStr,
    conint,
    constr,
    validator,
)


class ModelVersionManifest(BaseModel):
    """
    Model Version artifact.  # noqa: E501
    """

    description: Optional[constr(strict=True, max_length=512)] = Field(
        default=None,
        description="+label=Description +usage=Description of the artifact or model version +docs=Description of the artifact or model version",
    )
    metadata: Dict[str, Any] = Field(
        default=...,
        description="+label=Metadata +docs=Metadata for the artifact or model version +usage=Metadata for the artifact or model version +uiType=JsonInput",
    )
    version_alias: Optional[constr(strict=True, max_length=128)] = Field(
        default=None,
        description="+label=Version Alias +usage=The version alias for artifact or model version which should start with 'v' followed by alphanumeric and it can include '.' and '-' in between (e.g. v1.0.0, v-prod, v-dev, etc) +docs=The version alias for artifact or model version which should start with 'v' followed by alphanumeric and it can include '.' and '-' in between (e.g. v1.0.0, v-prod, v-dev, etc) +message=The version alias should start with 'v' followed by alphanumeric and it can include '.' and '-' in between (e.g. v1.0.0, v-prod, v-dev, etc)",
    )
    type: Optional[StrictStr] = "model-version"
    source: Source1 = Field(...)
    framework: Optional[Framework] = None
    environment: Optional[ModelVersionEnvironment] = None
    step: Optional[conint(strict=True, ge=0)] = Field(
        default=0, description="+label=Step"
    )
    __properties = [
        "description",
        "metadata",
        "version_alias",
        "type",
        "source",
        "framework",
        "environment",
        "step",
    ]

    @validator("version_alias")
    def version_alias_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^v[a-zA-Z0-9.-]*([a-zA-Z0-9]+)$", value):
            raise ValueError(
                r"must validate the regular expression /^v[a-zA-Z0-9.-]*([a-zA-Z0-9]+)$/"
            )
        return value

    @validator("type")
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ("model-version",):
            raise ValueError("must be one of enum values ('model-version')")
        return value

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> ModelVersionManifest:
        """Create an instance of ModelVersionManifest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of source
        if self.source:
            _dict["source"] = self.source.to_dict()
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of framework
        if self.framework:
            _dict["framework"] = self.framework.to_dict()
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of environment
        if self.environment:
            _dict["environment"] = self.environment.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> ModelVersionManifest:
        """Create an instance of ModelVersionManifest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return ModelVersionManifest.parse_obj(obj)

        _obj = ModelVersionManifest.parse_obj(
            {
                "description": obj.get("description"),
                "metadata": obj.get("metadata"),
                "version_alias": obj.get("version_alias"),
                "type": obj.get("type")
                if obj.get("type") is not None
                else "model-version",
                "source": Source1.from_dict(obj.get("source"))
                if obj.get("source") is not None
                else None,
                "framework": Framework.from_dict(obj.get("framework"))
                if obj.get("framework") is not None
                else None,
                "environment": ModelVersionEnvironment.from_dict(obj.get("environment"))
                if obj.get("environment") is not None
                else None,
                "step": obj.get("step") if obj.get("step") is not None else 0,
            }
        )
        return _obj
