# coding: utf-8

"""
    Moodle Webservice API

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

    The version of the OpenAPI document: 5.0.3 (Build: 20251006)
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.auth_email_signup_user_parameters_customprofilefields_inner import AuthEmailSignupUserParametersCustomprofilefieldsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class AuthEmailSignupUserParameters(BaseModel):
    """
    AuthEmailSignupUserParameters
    """ # noqa: E501
    city: Optional[StrictStr] = Field(default='', description="Home city of the user")
    country: Optional[StrictStr] = Field(default='', description="Home country code")
    customprofilefields: Optional[List[AuthEmailSignupUserParametersCustomprofilefieldsInner]] = Field(default=None, description="User custom fields (also known as user profile fields)")
    email: Optional[StrictStr] = Field(description="A valid and unique email address")
    firstname: Optional[StrictStr] = Field(description="The first name(s) of the user")
    lastname: Optional[StrictStr] = Field(description="The family name of the user")
    password: Optional[StrictStr] = Field(description="Plain text password")
    recaptchachallengehash: Optional[StrictStr] = Field(default='', description="Recaptcha challenge hash")
    recaptcharesponse: Optional[StrictStr] = Field(default='', description="Recaptcha response")
    redirect: Optional[StrictStr] = Field(default='', description="Redirect the user to this site url after confirmation.")
    username: Optional[StrictStr] = Field(description="Username")
    __properties: ClassVar[List[str]] = ["city", "country", "customprofilefields", "email", "firstname", "lastname", "password", "recaptchachallengehash", "recaptcharesponse", "redirect", "username"]

    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 AuthEmailSignupUserParameters 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 each item in customprofilefields (list)
        _items = []
        if self.customprofilefields:
            for _item_customprofilefields in self.customprofilefields:
                if _item_customprofilefields:
                    _items.append(_item_customprofilefields.to_dict())
            _dict['customprofilefields'] = _items
        # set to None if city (nullable) is None
        # and model_fields_set contains the field
        if self.city is None and "city" in self.model_fields_set:
            _dict['city'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "AuthEmailSignupUserParameters" in settings.relaxed_models

        if not isinstance(obj, dict):
            return cls.model_construct(**obj) if relaxed else cls.model_validate(obj)

        data = {
            "city": obj.get("city") if obj.get("city") is not None else '',
            "country": obj.get("country") if obj.get("country") is not None else '',
            "customprofilefields": [AuthEmailSignupUserParametersCustomprofilefieldsInner.from_dict(_item) for _item in obj["customprofilefields"]] if obj.get("customprofilefields") is not None else None,
            "email": obj.get("email"),
            "firstname": obj.get("firstname"),
            "lastname": obj.get("lastname"),
            "password": obj.get("password"),
            "recaptchachallengehash": obj.get("recaptchachallengehash") if obj.get("recaptchachallengehash") is not None else '',
            "recaptcharesponse": obj.get("recaptcharesponse") if obj.get("recaptcharesponse") is not None else '',
            "redirect": obj.get("redirect") if obj.get("redirect") is not None else '',
            "username": obj.get("username")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


