# coding: utf-8

"""
    Ory Identities API

    This is the API specification for Ory Identities with features such as registration, login, recovery, account verification, profile settings, password reset, identity management, session management, email and sms delivery, and more. 

    The version of the OpenAPI document: v1.3.7
    Contact: office@ory.sh
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from ory_kratos_client.models.o_auth2_client import OAuth2Client
from ory_kratos_client.models.o_auth2_consent_request_open_id_connect_context import OAuth2ConsentRequestOpenIDConnectContext
from typing import Optional, Set
from typing_extensions import Self

class OAuth2LoginRequest(BaseModel):
    """
    OAuth2LoginRequest struct for OAuth2LoginRequest
    """ # noqa: E501
    challenge: Optional[StrictStr] = Field(default=None, description="ID is the identifier (\\\"login challenge\\\") of the login request. It is used to identify the session.")
    client: Optional[OAuth2Client] = None
    oidc_context: Optional[OAuth2ConsentRequestOpenIDConnectContext] = None
    request_url: Optional[StrictStr] = Field(default=None, description="RequestURL is the original OAuth 2.0 Authorization URL requested by the OAuth 2.0 client. It is the URL which initiates the OAuth 2.0 Authorization Code or OAuth 2.0 Implicit flow. This URL is typically not needed, but might come in handy if you want to deal with additional request parameters.")
    requested_access_token_audience: Optional[List[StrictStr]] = None
    requested_scope: Optional[List[StrictStr]] = None
    session_id: Optional[StrictStr] = Field(default=None, description="SessionID is the login session ID. If the user-agent reuses a login session (via cookie / remember flag) this ID will remain the same. If the user-agent did not have an existing authentication session (e.g. remember is false) this will be a new random value. This value is used as the \\\"sid\\\" parameter in the ID Token and in OIDC Front-/Back- channel logout. It's value can generally be used to associate consecutive login requests by a certain user.")
    skip: Optional[StrictBool] = Field(default=None, description="Skip, if true, implies that the client has requested the same scopes from the same user previously. If true, you can skip asking the user to grant the requested scopes, and simply forward the user to the redirect URL.  This feature allows you to update / set session information.")
    subject: Optional[StrictStr] = Field(default=None, description="Subject is the user ID of the end-user that authenticated. Now, that end user needs to grant or deny the scope requested by the OAuth 2.0 client. If this value is set and `skip` is true, you MUST include this subject type when accepting the login request, or the request will fail.")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["challenge", "client", "oidc_context", "request_url", "requested_access_token_audience", "requested_scope", "session_id", "skip", "subject"]

    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 OAuth2LoginRequest 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of client
        if self.client:
            _dict['client'] = self.client.to_dict()
        # override the default output from pydantic by calling `to_dict()` of oidc_context
        if self.oidc_context:
            _dict['oidc_context'] = self.oidc_context.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "challenge": obj.get("challenge"),
            "client": OAuth2Client.from_dict(obj["client"]) if obj.get("client") is not None else None,
            "oidc_context": OAuth2ConsentRequestOpenIDConnectContext.from_dict(obj["oidc_context"]) if obj.get("oidc_context") is not None else None,
            "request_url": obj.get("request_url"),
            "requested_access_token_audience": obj.get("requested_access_token_audience"),
            "requested_scope": obj.get("requested_scope"),
            "session_id": obj.get("session_id"),
            "skip": obj.get("skip"),
            "subject": obj.get("subject")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


