from fastapi import APIRouter, Request
from app.core.settings import get_settings

router = APIRouter(tags=["system"])

@router.get("/health")
def health(request: Request):
    s = get_settings()
    return {
        "status": "ok",
        "app": s.APP_NAME,
        "env": s.ENV,
        "db_backend": s.DB_BACKEND,
        "context": {
            "tenant_code": getattr(request.state, "tenant_code", None),
            "branch_code": getattr(request.state, "branch_code", None),
            "year_code": getattr(request.state, "year_code", None),
        },
    }
