# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

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

class AiplacementEditorGenerateTextResponse(BaseModel):
    """
    AiplacementEditorGenerateTextResponse
    """ # noqa: E501
    error: Optional[StrictStr] = Field(default='', description="Error message if any")
    errorcode: Optional[StrictInt] = Field(default=0, description="Error code if any")
    finishreason: Optional[StrictStr] = Field(default='stop', description="The reason generation was stopped")
    generatedcontent: Optional[StrictStr] = Field(default=None, description="The text generated by AI.")
    prompttext: Optional[StrictStr] = Field(description="The prompt text for the AI service")
    success: Optional[StrictBool] = Field(description="Was the request successful")
    timecreated: Optional[StrictInt] = Field(description="The time the request was created")
    __properties: ClassVar[List[str]] = ["error", "errorcode", "finishreason", "generatedcontent", "prompttext", "success", "timecreated"]

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "error": obj.get("error") if obj.get("error") is not None else '',
            "errorcode": obj.get("errorcode") if obj.get("errorcode") is not None else 0,
            "finishreason": obj.get("finishreason") if obj.get("finishreason") is not None else 'stop',
            "generatedcontent": obj.get("generatedcontent"),
            "prompttext": obj.get("prompttext"),
            "success": obj.get("success"),
            "timecreated": obj.get("timecreated")
        })
        return _obj


