# coding: utf-8

"""
    HCX API

    The HCX REST API. Please see https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary for more details.

    The version of the OpenAPI document: 24.1.5
    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 pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from pyhcx.models.training_task_result_status_info import TrainingTaskResultStatusInfo
from typing import Optional, Set
from typing_extensions import Self

class TrainingTaskResult(BaseModel):
    """
    TrainingTaskResult
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Training ID")
    name: Optional[StrictStr] = Field(default=None, description="Training name")
    model: Optional[StrictStr] = Field(default=None, description="Tuning model name")
    method: Optional[StrictStr] = Field(default=None, description="Tuning technique")
    task_type: Optional[StrictStr] = Field(default=None, description="Task type", alias="taskType")
    train_epochs: Optional[StrictInt] = Field(default=None, description="Number of epochs for training", alias="trainEpochs")
    learning_rate: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Learning rate", alias="learningRate")
    status: Optional[StrictStr] = Field(default=None, description="Training status")
    status_info: Optional[TrainingTaskResultStatusInfo] = Field(default=None, alias="statusInfo")
    created_client_type: Optional[StrictStr] = Field(default=None, description="Client type that requested the training", alias="createdClientType")
    created_date: Optional[StrictStr] = Field(default=None, description="Training creation date (ISO 8601 format)", alias="createdDate")
    updated_date: Optional[StrictStr] = Field(default=None, description="Training update date (ISO 8601 format)", alias="updatedDate")
    __properties: ClassVar[List[str]] = ["id", "name", "model", "method", "taskType", "trainEpochs", "learningRate", "status", "statusInfo", "createdClientType", "createdDate", "updatedDate"]

    @field_validator('task_type')
    def task_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['GENERATION', 'CLASSIFICATION']):
            raise ValueError("must be one of enum values ('GENERATION', 'CLASSIFICATION')")
        return value

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['WAIT', 'RUNNING', 'FAILED', 'SUCCEEDED']):
            raise ValueError("must be one of enum values ('WAIT', 'RUNNING', 'FAILED', 'SUCCEEDED')")
        return value

    @field_validator('created_client_type')
    def created_client_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['API', 'WEB']):
            raise ValueError("must be one of enum values ('API', 'WEB')")
        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 TrainingTaskResult 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 status_info
        if self.status_info:
            _dict['statusInfo'] = self.status_info.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "model": obj.get("model"),
            "method": obj.get("method"),
            "taskType": obj.get("taskType"),
            "trainEpochs": obj.get("trainEpochs"),
            "learningRate": obj.get("learningRate"),
            "status": obj.get("status"),
            "statusInfo": TrainingTaskResultStatusInfo.from_dict(obj["statusInfo"]) if obj.get("statusInfo") is not None else None,
            "createdClientType": obj.get("createdClientType"),
            "createdDate": obj.get("createdDate"),
            "updatedDate": obj.get("updatedDate")
        })
        return _obj


