from fastapi import APIRouter, Depends, Request
from ...core.database import get_db
from ...core.permission import require_login

router = APIRouter()


@router.get("/law-article/{id}")
async def get_law_article(
    id: int,
    request: Request,
    user: dict = Depends(require_login),
    db=Depends(get_db),
):
    conn, cur = db

    try:
        await cur.execute("SELECT * FROM law_articles WHERE id = %s", (id,))
        row = await cur.fetchone()
        if row:
            return dict(row)
    except Exception:
        pass

    return {"error": "法规条文不存在", "detail": "law article not found"}
