# 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 typing import Any, Dict, Optional

from truefoundry.ml._autogen.client.models.experiment_tag_dto import ExperimentTagDto
from truefoundry.ml._autogen.client.models.subject import Subject
from truefoundry.pydantic_v1 import BaseModel, Field, StrictInt, StrictStr, conlist


class ExperimentDto(BaseModel):
    """
    ExperimentDto
    """

    experiment_id: StrictStr = Field(...)
    name: StrictStr = Field(...)
    storage_integration_id: Optional[StrictStr] = None
    artifact_location: Optional[StrictStr] = None
    lifecycle_stage: Optional[StrictStr] = None
    tags: Optional[conlist(ExperimentTagDto)] = None
    creator_user_id: StrictStr = Field(...)
    created_by_subject: Subject = Field(...)
    description: Optional[StrictStr] = None
    privacy_type: Optional[StrictStr] = "PRIVATE"
    created_at: Optional[StrictInt] = None
    tenant_name: Optional[StrictStr] = None
    manifest: Dict[str, Any] = Field(...)
    num_runs: Optional[StrictInt] = None
    artifact_type_counts: Optional[Dict[str, StrictInt]] = None
    datasets_count: Optional[StrictInt] = None
    num_user_collaborators: Optional[StrictInt] = None
    __properties = [
        "experiment_id",
        "name",
        "storage_integration_id",
        "artifact_location",
        "lifecycle_stage",
        "tags",
        "creator_user_id",
        "created_by_subject",
        "description",
        "privacy_type",
        "created_at",
        "tenant_name",
        "manifest",
        "num_runs",
        "artifact_type_counts",
        "datasets_count",
        "num_user_collaborators",
    ]

    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) -> ExperimentDto:
        """Create an instance of ExperimentDto 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 each item in tags (list)
        _items = []
        if self.tags:
            for _item in self.tags:
                if _item:
                    _items.append(_item.to_dict())
            _dict["tags"] = _items
        # 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()
        return _dict

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

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

        _obj = ExperimentDto.parse_obj(
            {
                "experiment_id": obj.get("experiment_id"),
                "name": obj.get("name"),
                "storage_integration_id": obj.get("storage_integration_id"),
                "artifact_location": obj.get("artifact_location"),
                "lifecycle_stage": obj.get("lifecycle_stage"),
                "tags": [ExperimentTagDto.from_dict(_item) for _item in obj.get("tags")]
                if obj.get("tags") is not None
                else None,
                "creator_user_id": obj.get("creator_user_id"),
                "created_by_subject": Subject.from_dict(obj.get("created_by_subject"))
                if obj.get("created_by_subject") is not None
                else None,
                "description": obj.get("description"),
                "privacy_type": obj.get("privacy_type")
                if obj.get("privacy_type") is not None
                else "PRIVATE",
                "created_at": obj.get("created_at"),
                "tenant_name": obj.get("tenant_name"),
                "manifest": obj.get("manifest"),
                "num_runs": obj.get("num_runs"),
                "artifact_type_counts": obj.get("artifact_type_counts"),
                "datasets_count": obj.get("datasets_count"),
                "num_user_collaborators": obj.get("num_user_collaborators"),
            }
        )
        return _obj
