# coding: utf-8

"""
    Rapidata Asset API

    The API for the Rapidata Asset service

    The version of the OpenAPI document: v1
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from rapidata.api_client.models.i_asset_input import IAssetInput
from typing import Optional, Set
from typing_extensions import Self

class CreateDatapointModel(BaseModel):
    """
    The body request for creating a new datapoint
    """ # noqa: E501
    asset: IAssetInput = Field(description="The asset within the datapoint")
    context: Optional[StrictStr] = Field(default=None, description="An additional context to show the users when solving the rapid.")
    context_asset: Optional[IAssetInput] = Field(default=None, description="ContextAsset", alias="contextAsset")
    sort_index: Optional[StrictInt] = Field(default=None, description="The sort index represents the order of the datapoint in the dataset", alias="sortIndex")
    group: Optional[StrictStr] = Field(default=None, description="The group a datapoint belongs to.")
    transcription: Optional[StrictStr] = Field(default=None, description="For audio or video assets, an optional transcription of the content.")
    private_metadata: Optional[Dict[str, StrictStr]] = Field(default=None, description="Private metadata for internal tracking. Not displayed to users.", alias="privateMetadata")
    __properties: ClassVar[List[str]] = ["asset", "context", "contextAsset", "sortIndex", "group", "transcription", "privateMetadata"]

    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 CreateDatapointModel 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 asset
        if self.asset:
            _dict['asset'] = self.asset.to_dict()
        # override the default output from pydantic by calling `to_dict()` of context_asset
        if self.context_asset:
            _dict['contextAsset'] = self.context_asset.to_dict()
        # set to None if context (nullable) is None
        # and model_fields_set contains the field
        if self.context is None and "context" in self.model_fields_set:
            _dict['context'] = None

        # set to None if group (nullable) is None
        # and model_fields_set contains the field
        if self.group is None and "group" in self.model_fields_set:
            _dict['group'] = None

        # set to None if transcription (nullable) is None
        # and model_fields_set contains the field
        if self.transcription is None and "transcription" in self.model_fields_set:
            _dict['transcription'] = None

        # set to None if private_metadata (nullable) is None
        # and model_fields_set contains the field
        if self.private_metadata is None and "private_metadata" in self.model_fields_set:
            _dict['privateMetadata'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "asset": IAssetInput.from_dict(obj["asset"]) if obj.get("asset") is not None else None,
            "context": obj.get("context"),
            "contextAsset": IAssetInput.from_dict(obj["contextAsset"]) if obj.get("contextAsset") is not None else None,
            "sortIndex": obj.get("sortIndex"),
            "group": obj.get("group"),
            "transcription": obj.get("transcription"),
            "privateMetadata": obj.get("privateMetadata")
        })
        return _obj


