"""
FreeExile Design Pipeline Types & Data Transfer Objects (DTOs).
Defines standard enums, data contracts, and helper methods for the Design Pipeline.
"""

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Any


class RequestStatus(str, Enum):
    INBOX = "inbox"
    IN_PROGRESS = "in_progress"
    PENDING_REVIEW = "pending_review"
    APPROVED = "approved"
    REJECTED = "rejected"


class AssetCategory(str, Enum):
    CONCEPT = "concept"
    SPRITE = "sprite"
    VFX = "vfx"
    UI = "ui"
    PIPELINE = "pipeline"


class Priority(str, Enum):
    CRITICAL = "critical"
    HIGH = "high"
    MEDIUM = "medium"
    LOW = "low"

    @property
    def rank(self) -> int:
        mapping = {"critical": 0, "high": 1, "medium": 2, "low": 3}
        return mapping[self.value]


class ApprovalVerdict(str, Enum):
    PASS = "pass"
    FAIL = "fail"
    APPROVE = "approve"
    REJECT = "reject"


@dataclass(slots=True, frozen=True)
class DesignRequest:
    request_id: str
    title: str
    source_doc: str
    requesting_dept: str
    category: AssetCategory
    priority: Priority
    assigned_agent: str
    status: RequestStatus
    created_at: str
    target_sla: str
    file_path: Path


@dataclass(slots=True, frozen=True)
class AssetDeliverable:
    relative_path: str
    file_size_bytes: int
    width: int
    height: int
    format: str
    is_power_of_two: bool
    has_normal_map: bool


@dataclass(slots=True, frozen=True)
class AuditReport:
    request_id: str
    stage: str  # "QA_TECHNICAL" or "CEO_AESTHETIC"
    verdict: ApprovalVerdict
    auditor: str
    timestamp: str
    notes: str
    details: dict[str, Any]


def is_power_of_two(n: int) -> bool:
    """Checks if positive integer is a power of 2."""
    return n > 0 and (n & (n - 1)) == 0
