# coding: utf-8

"""
TrueFoundry ML API

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

The version of the OpenAPI document: 1.0.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 datetime import datetime
from typing import Any, Dict, Optional

from truefoundry.ml._autogen.client.models.artifact_version_serialization_format import (
    ArtifactVersionSerializationFormat,
)
from truefoundry.ml._autogen.client.models.artifact_version_status import (
    ArtifactVersionStatus,
)
from truefoundry.ml._autogen.client.models.manifest1 import Manifest1
from truefoundry.ml._autogen.client.models.subject import Subject
from truefoundry.pydantic_v1 import BaseModel, Field, StrictInt, StrictStr


class ArtifactVersionDto(BaseModel):
    """
    ArtifactVersionDto
    """

    id: StrictStr = Field(...)
    artifact_id: StrictStr = Field(...)
    version: StrictInt = Field(...)
    fqn: StrictStr = Field(...)
    experiment_id: StrictStr = Field(...)
    artifact_storage_root: Optional[StrictStr] = None
    artifact_metadata: Optional[Dict[str, Any]] = None
    description: Optional[StrictStr] = None
    status: Optional[ArtifactVersionStatus] = None
    step: Optional[StrictInt] = 0
    created_by: Optional[StrictStr] = None
    created_by_subject: Subject = Field(...)
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    artifact_fqn: Optional[StrictStr] = None
    data_path: Optional[StrictStr] = None
    usage_code_snippet: Optional[StrictStr] = None
    run_id: Optional[StrictStr] = None
    artifact_name: Optional[StrictStr] = None
    internal_metadata: Optional[Dict[str, Any]] = None
    artifact_size: Optional[StrictInt] = None
    manifest: Optional[Manifest1] = None
    serialization_format: ArtifactVersionSerializationFormat = Field(...)
    __properties = [
        "id",
        "artifact_id",
        "version",
        "fqn",
        "experiment_id",
        "artifact_storage_root",
        "artifact_metadata",
        "description",
        "status",
        "step",
        "created_by",
        "created_by_subject",
        "created_at",
        "updated_at",
        "artifact_fqn",
        "data_path",
        "usage_code_snippet",
        "run_id",
        "artifact_name",
        "internal_metadata",
        "artifact_size",
        "manifest",
        "serialization_format",
    ]

    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) -> ArtifactVersionDto:
        """Create an instance of ArtifactVersionDto 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 created_by_subject
        if self.created_by_subject:
            _dict["created_by_subject"] = self.created_by_subject.to_dict()
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of manifest
        if self.manifest:
            _dict["manifest"] = self.manifest.to_dict()
        return _dict

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

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

        _obj = ArtifactVersionDto.parse_obj(
            {
                "id": obj.get("id"),
                "artifact_id": obj.get("artifact_id"),
                "version": obj.get("version"),
                "fqn": obj.get("fqn"),
                "experiment_id": obj.get("experiment_id"),
                "artifact_storage_root": obj.get("artifact_storage_root"),
                "artifact_metadata": obj.get("artifact_metadata"),
                "description": obj.get("description"),
                "status": obj.get("status"),
                "step": obj.get("step") if obj.get("step") is not None else 0,
                "created_by": obj.get("created_by"),
                "created_by_subject": Subject.from_dict(obj.get("created_by_subject"))
                if obj.get("created_by_subject") is not None
                else None,
                "created_at": obj.get("created_at"),
                "updated_at": obj.get("updated_at"),
                "artifact_fqn": obj.get("artifact_fqn"),
                "data_path": obj.get("data_path"),
                "usage_code_snippet": obj.get("usage_code_snippet"),
                "run_id": obj.get("run_id"),
                "artifact_name": obj.get("artifact_name"),
                "internal_metadata": obj.get("internal_metadata"),
                "artifact_size": obj.get("artifact_size"),
                "manifest": Manifest1.from_dict(obj.get("manifest"))
                if obj.get("manifest") is not None
                else None,
                "serialization_format": obj.get("serialization_format"),
            }
        )
        return _obj
