"""Type definitions for Synor Compute SDK."""

from enum import Enum
from typing import Optional
from pydantic import BaseModel


class ProcessorType(str, Enum):
    """Supported processor types."""
    CPU = "cpu"
    GPU = "gpu"
    TPU = "tpu"
    NPU = "npu"
    LPU = "lpu"
    FPGA = "fpga"
    WASM = "wasm"
    WEBGPU = "webgpu"


class Precision(str, Enum):
    """Precision levels for compute operations."""
    FP64 = "fp64"
    FP32 = "fp32"
    FP16 = "fp16"
    BF16 = "bf16"
    INT8 = "int8"
    INT4 = "int4"


class BalancingStrategy(str, Enum):
    """Balancing strategy for job scheduling."""
    SPEED = "speed"      # Minimize execution time
    COST = "cost"        # Minimize cost
    ENERGY = "energy"    # Minimize energy consumption
    LATENCY = "latency"  # Minimize latency
    BALANCED = "balanced"  # Balance all factors


class TaskPriority(str, Enum):
    """Task priority levels."""
    CRITICAL = "critical"
    HIGH = "high"
    NORMAL = "normal"
    BACKGROUND = "background"


class JobStatus(str, Enum):
    """Job status."""
    PENDING = "pending"
    QUEUED = "queued"
    RUNNING = "running"
    COMPLETED = "completed"
    FAILED = "failed"
    CANCELLED = "cancelled"


class SynorConfig(BaseModel):
    """SDK configuration."""
    api_key: str
    endpoint: str = "https://compute.synor.cc/api/v1"
    strategy: BalancingStrategy = BalancingStrategy.BALANCED
    precision: Precision = Precision.FP32
    timeout: float = 30.0
    debug: bool = False


class JobMetrics(BaseModel):
    """Job execution metrics."""
    execution_time_ms: float
    queue_time_ms: float
    processor_type: ProcessorType
    processor_id: str
    flops: float
    memory_bytes: int
    cost_micro: int
    energy_mj: float


class JobResult(BaseModel):
    """Job submission result."""
    job_id: str
    status: JobStatus
    data: Optional[dict] = None
    error: Optional[str] = None
    metrics: Optional[JobMetrics] = None


class PricingInfo(BaseModel):
    """Compute pricing info."""
    processor_type: ProcessorType
    spot_price: float  # microcredits per GFLOP
    avg_price_24h: float
    aws_equivalent: float
    savings_percent: float
