"""Public (unauthenticated) cPanel pricing endpoint."""
from __future__ import annotations

from typing import List

from fastapi import APIRouter, Depends
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from core.database import get_db
from models.cpanel import CpanelPackage
from schemas.cpanel import CpanelPackageOut

router = APIRouter(prefix="/api/v1/public/cpanel", tags=["cpanel-public"])


@router.get("/packages", response_model=List[CpanelPackageOut])
async def list_public_packages(db: AsyncSession = Depends(get_db)) -> List[CpanelPackage]:
    stmt = (
        select(CpanelPackage)
        .where(CpanelPackage.is_active.is_(True))
        .order_by(CpanelPackage.sort_order, CpanelPackage.id)
    )
    return list((await db.execute(stmt)).scalars().all())