from django.http import JsonResponse
from django.urls import path
from django.db import connection

from apps.core.api_views import StaffOverviewView


def health(_request):
    db_ok = True
    try:
        with connection.cursor() as cursor:
            cursor.execute("SELECT 1")
    except Exception:
        db_ok = False
    status = 200 if db_ok else 503
    return JsonResponse(
        {
            "success": db_ok,
            "service": "shopno-holdings-api",
            "version": "v1",
            "database": "ok" if db_ok else "error",
        },
        status=status,
    )


urlpatterns = [
    path("health/", health, name="health"),
    path("admin/overview/", StaffOverviewView.as_view(), name="staff-overview"),
]
