# coding: utf-8

"""
    Connect API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    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 trinsic_api.models.disclosed_fields import DisclosedFields
from trinsic_api.models.session_fail_code import SessionFailCode
from trinsic_api.models.session_state import SessionState
from trinsic_api.models.verification import Verification
from typing import Optional, Set
from typing_extensions import Self

class Session(BaseModel):
    """
    Session
    """ # noqa: E501
    id: StrictStr
    state: SessionState = Field(description="The state of the session")
    fail_code: Optional[SessionFailCode] = Field(default=None, description="If the session is in state `IdvFailed`, this field contains the reason for failure.", alias="failCode")
    verification: Verification = Field(description="The underlying verification for this Session")
    disclosed_fields: DisclosedFields = Field(description="The fields that were requested to be disclosed when the Session was created", alias="disclosedFields")
    created: StrictInt = Field(description="The unix timestamp, in seconds, when this session was created")
    updated: StrictInt = Field(description="The unix timestamp, in seconds, when this session's state last changed")
    __properties: ClassVar[List[str]] = ["id", "state", "failCode", "verification", "disclosedFields", "created", "updated"]

    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 Session 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 verification
        if self.verification:
            _dict['verification'] = self.verification.to_dict()
        # override the default output from pydantic by calling `to_dict()` of disclosed_fields
        if self.disclosed_fields:
            _dict['disclosedFields'] = self.disclosed_fields.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "state": obj.get("state"),
            "failCode": obj.get("failCode"),
            "verification": Verification.from_dict(obj["verification"]) if obj.get("verification") is not None else None,
            "disclosedFields": DisclosedFields.from_dict(obj["disclosedFields"]) if obj.get("disclosedFields") is not None else None,
            "created": obj.get("created"),
            "updated": obj.get("updated")
        })
        return _obj


