# 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 cast
from typing import Any, Dict, List, Literal, Optional
from workos._types import _raise_deserialize_error
from workos._types import _format_datetime, _parse_datetime

from .flag_created_data_owner import FlagCreatedDataOwner


@dataclass(slots=True)
class FlagCreatedData:
    """The event payload."""

    object: Literal["feature_flag"]
    id: str
    """Unique identifier of the Feature Flag."""
    environment_id: str
    """The ID of the environment the Feature Flag belongs to."""
    slug: str
    """A unique key to reference the Feature Flag."""
    name: str
    """A descriptive name for the Feature Flag."""
    description: Optional[str]
    """A description for the Feature Flag."""
    owner: Optional["FlagCreatedDataOwner"]
    """The owner of the Feature Flag."""
    tags: List[str]
    """Labels assigned to the Feature Flag for categorizing and filtering."""
    enabled: bool
    """Specifies whether the Feature Flag is active for the current environment."""
    default_value: bool
    """The value returned for users and organizations who don't match any configured targeting rules."""
    created_at: datetime
    """An ISO 8601 timestamp."""
    updated_at: datetime
    """An ISO 8601 timestamp."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "FlagCreatedData":
        """Deserialize from a dictionary."""
        try:
            return cls(
                object=data.get("object", "feature_flag"),
                id=data["id"],
                environment_id=data["environment_id"],
                slug=data["slug"],
                name=data["name"],
                description=data["description"],
                owner=FlagCreatedDataOwner.from_dict(cast(Dict[str, Any], _v_owner))
                if (_v_owner := data["owner"]) is not None
                else None,
                tags=data["tags"],
                enabled=data["enabled"],
                default_value=data["default_value"],
                created_at=_parse_datetime(data["created_at"]),
                updated_at=_parse_datetime(data["updated_at"]),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("FlagCreatedData", 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["environment_id"] = self.environment_id
        result["slug"] = self.slug
        result["name"] = self.name
        if self.description is not None:
            result["description"] = self.description
        else:
            result["description"] = None
        if self.owner is not None:
            result["owner"] = self.owner.to_dict()
        else:
            result["owner"] = None
        result["tags"] = self.tags
        result["enabled"] = self.enabled
        result["default_value"] = self.default_value
        result["created_at"] = _format_datetime(self.created_at)
        result["updated_at"] = _format_datetime(self.updated_at)
        return result
