"""Result of listing activations for a license."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Any


@dataclass(frozen=True)
class ActivationsResult:
    """Result of listing activations for a license."""

    activations: list[dict[str, Any]]
    count: int
    limit: int | None

    def get_active_activations(self) -> list[dict[str, Any]]:
        """Get only active activations."""
        return [a for a in self.activations if a.get("status") == "active"]

    def get_active_count(self) -> int:
        """Get the number of active activations."""
        return len(self.get_active_activations())

    def has_activation(self, identifier: str) -> bool:
        """Check if an activation with the given identifier exists."""
        return any(a.get("identifier") == identifier for a in self.activations)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a plain dictionary."""
        return {
            "activations": self.activations,
            "count": self.count,
            "limit": self.limit,
        }
