# coding: utf-8

"""
    AccessibleTranslator SDK API

    Official SDK API for AccessibleTranslator - automated cognitive accessibility

    The version of the OpenAPI document: 1.1.0
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class TranslationResponse(BaseModel):
    """
    Response model for text translation API
    """ # noqa: E501
    translated_text: StrictStr
    explanations: Optional[StrictStr] = None
    input_language: StrictStr
    output_language: StrictStr
    input_word_count: StrictInt
    processing_time_ms: StrictInt
    word_balance: StrictInt
    words_used: StrictInt
    __properties: ClassVar[List[str]] = ["translated_text", "explanations", "input_language", "output_language", "input_word_count", "processing_time_ms", "word_balance", "words_used"]

    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 TranslationResponse 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,
        )
        # set to None if explanations (nullable) is None
        # and model_fields_set contains the field
        if self.explanations is None and "explanations" in self.model_fields_set:
            _dict['explanations'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "translated_text": obj.get("translated_text"),
            "explanations": obj.get("explanations"),
            "input_language": obj.get("input_language"),
            "output_language": obj.get("output_language"),
            "input_word_count": obj.get("input_word_count"),
            "processing_time_ms": obj.get("processing_time_ms"),
            "word_balance": obj.get("word_balance"),
            "words_used": obj.get("words_used")
        })
        return _obj


