from fastapi import APIRouter, Depends, Request
from fastapi.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer

castle_generic_router = APIRouter(tags=["castle"])


@castle_generic_router.get(
    "/", description="Castle accounting home page", response_class=HTMLResponse
)
async def index(
    request: Request,
    user: User = Depends(check_user_exists),
):
    return template_renderer(["castle/templates"]).TemplateResponse(
        request, "castle/index.html", {"user": user.json()}
    )
