# 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, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime
from .organization_domain_state import OrganizationDomainState
from .organization_domain_verification_strategy import (
    OrganizationDomainVerificationStrategy,
)


@dataclass(slots=True)
class OrganizationDomain:
    """Organization Domain model."""

    object: Literal["organization_domain"]
    """Distinguishes the organization domain object."""
    id: str
    """Unique identifier of the organization domain."""
    organization_id: str
    """ID of the parent Organization."""
    domain: str
    """Domain for the organization domain."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""
    state: Optional["OrganizationDomainState"] = None
    """Verification state of the domain."""
    verification_prefix: Optional[str] = None
    """The prefix used in DNS verification."""
    verification_token: Optional[str] = None
    """Validation token to be used in DNS TXT record."""
    verification_strategy: Optional["OrganizationDomainVerificationStrategy"] = None
    """Strategy used to verify the domain."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "OrganizationDomain":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "organization_domain"),
                id=data["id"],
                organization_id=data["organization_id"],
                domain=data["domain"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
                state=OrganizationDomainState(_v_state)
                if (_v_state := data.get("state")) is not None
                else None,
                verification_prefix=data.get("verification_prefix"),
                verification_token=data.get("verification_token"),
                verification_strategy=OrganizationDomainVerificationStrategy(
                    _v_verification_strategy
                )
                if (_v_verification_strategy := data.get("verification_strategy"))
                is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("OrganizationDomain", 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["organization_id"] = self.organization_id
        result["domain"] = self.domain
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        if self.state is not None:
            result["state"] = (
                self.state.value if isinstance(self.state, Enum) else self.state
            )
        if self.verification_prefix is not None:
            result["verification_prefix"] = self.verification_prefix
        if self.verification_token is not None:
            result["verification_token"] = self.verification_token
        if self.verification_strategy is not None:
            result["verification_strategy"] = (
                self.verification_strategy.value
                if isinstance(self.verification_strategy, Enum)
                else self.verification_strategy
            )
        return result
