# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime


@dataclass(slots=True)
class NewConnectApplicationSecret:
    """New Connect Application Secret model."""

    object: Literal["connect_application_secret"]
    """Distinguishes the connect application secret object."""
    id: str
    """The unique ID of the client secret."""
    secret_hint: str
    """A hint showing the last few characters of the secret value."""
    last_used_at: Optional[datetime]
    """The timestamp when the client secret was last used, or null if never used."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    secret: str
    """The plaintext secret value. Only returned at creation time and cannot be retrieved later."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "NewConnectApplicationSecret":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "connect_application_secret"),
                id=data["id"],
                secret_hint=data["secret_hint"],
                last_used_at=_parse_datetime(_v_last_used_at)
                if (_v_last_used_at := data["last_used_at"]) is not None
                else None,
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                secret=data["secret"],
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("NewConnectApplicationSecret", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["object"] = self.object
        result["id"] = self.id
        result["secret_hint"] = self.secret_hint
        if self.last_used_at is not None:
            result["last_used_at"] = _format_datetime(self.last_used_at)
        else:
            result["last_used_at"] = None
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        result["secret"] = self.secret
        return result
