"""주간 회고(weekly_review) 조회 엔드포인트."""
from fastapi import APIRouter, HTTPException
from .. import db

router = APIRouter(prefix="/api/lotto/review")


@router.get("/latest")
def latest():
    r = db.get_latest_review()
    if not r:
        raise HTTPException(404, "no review yet")
    return r


@router.get("/history")
def history(limit: int = 10):
    return {"reviews": db.list_reviews(limit)}


@router.get("/{draw_no}")
def get_one(draw_no: int):
    r = db.get_review(draw_no)
    if not r:
        raise HTTPException(404, f"no review for draw {draw_no}")
    return r
