# NIKAME GENERATED — DO NOT EDIT DIRECTLY
import secrets
from datetime import datetime, timedelta
from typing import Optional
from fastapi import Security, HTTPException, status
from fastapi.security.api_key import APIKeyHeader
from app.db.session import SessionLocal

# This would normally be a proper SQLA model. 
# For the template, we assume an 'ApiKey' model exists.

api_key_header = APIKeyHeader(name="X-API-KEY", auto_error=False)

async def get_api_key(api_key: str = Security(api_key_header)):
    if not api_key:
        raise HTTPException(status_code=403, detail="API Key missing")
    
    # In a real app, verify against DB
    # Example:
    # async with SessionLocal() as db:
    #     key = await db.execute(select(ApiKey).where(ApiKey.key == api_key))
    #     if not key: raise HTTPException(...)
    
    return api_key

def generate_key():
    return f"nk_{secrets.token_urlsafe(32)}"
