from typing import Optional
from fastapi import APIRouter, Request
from fastapi.templating import Jinja2Templates

from src.db.models.admin import Permission, Profile
from src.db.session import SessionDep

templates = Jinja2Templates(directory="src/templates")
router = APIRouter(include_in_schema=False, prefix="/admin")

@router.get("/profiles")
def get_profiles(db: SessionDep, request: Request, msg: Optional[str] = None):
    profiles = db.query(Profile).all()
    return templates.TemplateResponse("admin/profiles.html", {"request": request, "msg": msg, "profiles": profiles})

@router.get("/profiles/{profile_id}")
def comic_details(profile_id: str, request: Request, db: SessionDep):
    profile = db.get(Profile, profile_id)
    return templates.TemplateResponse("admin/profile_detail.html", {"request": request, "profile":profile})

@router.get("/permissions")
def get_permissions(db: SessionDep, request: Request, msg: Optional[str] = None):
    permissions = db.query(Permission).all()
    return templates.TemplateResponse("admin/permissions.html", {"request": request, "msg": msg, "permissions": permissions})

@router.get("/permissions/{permission_id}")
def artist_detail(permission_id: str, request: Request, db: SessionDep):
    permission= db.get(Permission, str(permission_id))
    return templates.TemplateResponse("comic/permission_detail.html", {"request": request, "permission": permission})
