# 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, Literal

from workos._types import _format_datetime, _parse_datetime, _raise_deserialize_error


@dataclass(slots=True)
class CORSOriginResponse:
    """CORS Origin Response model."""

    object: Literal["cors_origin"]
    """Distinguishes the CORS origin object."""
    id: str
    """Unique identifier of the CORS origin."""
    origin: str
    """The origin URL."""
    created_at: datetime
    """Timestamp when the CORS origin was created."""
    updated_at: datetime
    """Timestamp when the CORS origin was last updated."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> CORSOriginResponse:
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "cors_origin"),
                id=data["id"],
                origin=data["origin"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CORSOriginResponse", 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["origin"] = self.origin
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
