# backend/routers/dashboard_tabs.py
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from backend.database import get_db
from backend.services.snapshot import emit_status_snapshot

router = APIRouter(prefix="/dashboard", tags=["dashboard-tabs"])

@router.get("/active")
def get_active_units(db: Session = Depends(get_db)):
    """
    Return only ACTIVE (deployed) units for dashboard table swap.
    """
    snap = emit_status_snapshot()
    units = {
        uid: u
        for uid, u in snap["units"].items()
        if u["deployed"] is True
    }
    return {"units": units}

@router.get("/benched")
def get_benched_units(db: Session = Depends(get_db)):
    """
    Return only BENCHED (not deployed) units for dashboard table swap.
    """
    snap = emit_status_snapshot()
    units = {
        uid: u
        for uid, u in snap["units"].items()
        if u["deployed"] is False
    }
    return {"units": units}
