# 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.source1 import Source1
from truefoundry.pydantic_v1 import BaseModel, Field, StrictStr, constr, validator


class DataDirectoryManifest(BaseModel):
    """
    Data Directory manifest.  # noqa: E501
    """

    type: Optional[StrictStr] = "data-dir"
    name: constr(strict=True, max_length=256) = Field(
        default=..., description="Name of the data directory"
    )
    ml_repo: constr(strict=True) = Field(
        default=...,
        description="Name of the ML Repo to create the data directory under",
    )
    description: Optional[constr(strict=True, max_length=512)] = Field(
        default=None, description="Description for the data directory"
    )
    metadata: Dict[str, Any] = Field(
        default=...,
        description='Key Value metadata. Should be valid JSON. For e.g. `{"business-unit": "sales", "quality": "good", "rating": 4.5}`',
    )
    source: Source1 = Field(...)
    __properties = ["type", "name", "ml_repo", "description", "metadata", "source"]

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

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

    @validator("name")
    def name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[A-Za-z0-9_\-]+$", value):
            raise ValueError(
                r"must validate the regular expression /^[A-Za-z0-9_\-]+$/"
            )
        return value

    @validator("ml_repo")
    def ml_repo_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-zA-Z][a-zA-Z0-9\-]{1,98}[a-zA-Z0-9]$", value):
            raise ValueError(
                r"must validate the regular expression /^[a-zA-Z][a-zA-Z0-9\-]{1,98}[a-zA-Z0-9]$/"
            )
        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) -> DataDirectoryManifest:
        """Create an instance of DataDirectoryManifest 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()
        return _dict

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

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

        _obj = DataDirectoryManifest.parse_obj(
            {
                "type": obj.get("type") if obj.get("type") is not None else "data-dir",
                "name": obj.get("name"),
                "ml_repo": obj.get("ml_repo"),
                "description": obj.get("description"),
                "metadata": obj.get("metadata"),
                "source": Source1.from_dict(obj.get("source"))
                if obj.get("source") is not None
                else None,
            }
        )
        return _obj
