"""Data classes for cleanup service reports.

Extracted from ``cleanup_service.py`` to keep that module under the
500-line limit per CONTRIBUTING (F8 fix).
"""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any

__all__ = [
    "CleanupReport",
    "ResourceCleanupSummary",
    "StaleItem",
]


@dataclass(slots=True)
class StaleItem:
    """A single item identified for cleanup."""

    resource_type: str
    path: str
    age_description: str
    plan_id: str | None = None


@dataclass(slots=True)
class ResourceCleanupSummary:
    """Per-resource-type cleanup result."""

    resource_type: str
    scanned: int = 0
    removed: int = 0
    skipped: int = 0
    skipped_reasons: list[str] = field(default_factory=list)


@dataclass(slots=True)
class CleanupReport:
    """Full cleanup report across all resource types."""

    dry_run: bool = False
    sandboxes: ResourceCleanupSummary = field(
        default_factory=lambda: ResourceCleanupSummary(resource_type="sandboxes"),
    )
    checkpoints: ResourceCleanupSummary = field(
        default_factory=lambda: ResourceCleanupSummary(resource_type="checkpoints"),
    )
    sessions: ResourceCleanupSummary = field(
        default_factory=lambda: ResourceCleanupSummary(resource_type="sessions"),
    )
    logs: ResourceCleanupSummary = field(
        default_factory=lambda: ResourceCleanupSummary(resource_type="logs"),
    )
    backups: ResourceCleanupSummary = field(
        default_factory=lambda: ResourceCleanupSummary(resource_type="backups"),
    )
    stale_items: list[StaleItem] = field(default_factory=list)

    def as_dict(self) -> dict[str, Any]:
        """Serialize the report for CLI output."""
        return {
            "dry_run": self.dry_run,
            "sandboxes": {
                "scanned": self.sandboxes.scanned,
                "removed": self.sandboxes.removed,
                "skipped": self.sandboxes.skipped,
            },
            "checkpoints": {
                "scanned": self.checkpoints.scanned,
                "removed": self.checkpoints.removed,
                "skipped": self.checkpoints.skipped,
            },
            "sessions": {
                "scanned": self.sessions.scanned,
                "removed": self.sessions.removed,
                "skipped": self.sessions.skipped,
            },
            "logs": {
                "scanned": self.logs.scanned,
                "removed": self.logs.removed,
                "skipped": self.logs.skipped,
            },
            "backups": {
                "scanned": self.backups.scanned,
                "removed": self.backups.removed,
                "skipped": self.backups.skipped,
            },
        }
