from __future__ import annotations

from fastapi import APIRouter, Depends, Request
from fastapi.responses import HTMLResponse

from dependencies import require_any_role_html, require_roles_html
from models import User
from routes.template_filters import create_templates

router = APIRouter(tags=["UI"])
templates = create_templates()

READ_ROLES = ("viewer", "analyst", "project_manager", "admin")
MANAGE_ROLES = ("project_manager", "admin")


@router.get(
    "/ui/simulations",
    response_class=HTMLResponse,
    include_in_schema=False,
    name="ui.simulations",
)
def simulations_dashboard(
    request: Request,
    _: User = Depends(require_any_role_html(*READ_ROLES)),
) -> HTMLResponse:
    return templates.TemplateResponse(
        request,
        "simulations.html",
        {
            "title": "Simulations",
        },
    )


@router.get(
    "/ui/reporting",
    response_class=HTMLResponse,
    include_in_schema=False,
    name="ui.reporting",
)
def reporting_dashboard(
    request: Request,
    _: User = Depends(require_any_role_html(*READ_ROLES)),
) -> HTMLResponse:
    return templates.TemplateResponse(
        request,
        "reporting.html",
        {
            "title": "Reporting",
        },
    )


@router.get(
    "/ui/settings",
    response_class=HTMLResponse,
    include_in_schema=False,
    name="ui.settings",
)
def settings_page(
    request: Request,
    _: User = Depends(require_any_role_html(*READ_ROLES)),
) -> HTMLResponse:
    return templates.TemplateResponse(
        request,
        "settings.html",
        {
            "title": "Settings",
        },
    )


@router.get(
    "/theme-settings",
    response_class=HTMLResponse,
    include_in_schema=False,
    name="ui.theme_settings",
)
def theme_settings_page(
    request: Request,
    _: User = Depends(require_any_role_html(*READ_ROLES)),
) -> HTMLResponse:
    return templates.TemplateResponse(
        request,
        "theme_settings.html",
        {
            "title": "Theme Settings",
        },
    )


@router.get(
    "/ui/currencies",
    response_class=HTMLResponse,
    include_in_schema=False,
    name="ui.currencies",
)
def currencies_page(
    request: Request,
    _: User = Depends(require_roles_html(*MANAGE_ROLES)),
) -> HTMLResponse:
    return templates.TemplateResponse(
        request,
        "currencies.html",
        {
            "title": "Currency Management",
        },
    )
