"""Dependencies for FastAPI routes."""

import logging
from fastapi import Depends, HTTPException, Header
from typing import Optional
from dbmodel import pacs_db, UserToken, User
import jwt

LOGGER = logging.getLogger('sampacs')

# Секретный ключ для JWT (должен совпадать с auth.py)
JWT_SECRET = "your-secret-key-here"
JWT_ALGORITHM = "HS256"

async def get_db():
    """Database dependency that manages connection for each request."""
    LOGGER.debug("DB: Opening database connection")
    pacs_db.connect(reuse_if_open=True)
    try:
        yield
    finally:
        if not pacs_db.is_closed():
            pacs_db.close()
            LOGGER.debug("DB: Closing database connection")
