from django.http import Http404
from django.shortcuts import render


def serve_engine_page(request, slug):
    """
    Dedicated route for Template Engine pages.
    Avoids root-level slug collisions with catalogue/detail routes.
    """
    try:
        from ocyan.plugin.template_engine.engine.models.pages import EnginePage
    except Exception as exc:
        raise Http404("Template Engine is unavailable") from exc

    page = EnginePage.objects.live().public().filter(slug=slug).first()
    if page is None:
        raise Http404("Engine page not found")

    return page.specific.serve(request)


def startup(request):
    return render(request, "ocyan/startup.html")
