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

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Any, Dict
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from .connection_saml_certificate_renewed_data_certificate_certificate_type import (
    ConnectionSAMLCertificateRenewedDataCertificateCertificateType,
)


@dataclass(slots=True)
class ConnectionSAMLCertificateRenewedDataCertificate:
    """The renewed SAML certificate details."""

    certificate_type: "ConnectionSAMLCertificateRenewedDataCertificateCertificateType"
    """The type of the SAML certificate."""
    expiry_date: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(
        cls, data: Dict[str, Any]
    ) -> "ConnectionSAMLCertificateRenewedDataCertificate":
        """Deserialize from a dictionary."""
        try:
            return cls(
                certificate_type=ConnectionSAMLCertificateRenewedDataCertificateCertificateType(
                    data["certificate_type"]
                ),
                expiry_date=_parse_datetime(data["expiry_date"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error(
                "ConnectionSAMLCertificateRenewedDataCertificate", e
            )

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["certificate_type"] = (
            self.certificate_type.value
            if isinstance(self.certificate_type, Enum)
            else self.certificate_type
        )
        result["expiry_date"] = _format_datetime(self.expiry_date)
        return result
