from routes.handeling.errorsAndBots import maybe_a_hacker

from my_modules.app.constens import THE_IP_BOT_MANAGER, SKIP_PATH_PREFIXES, SKIP_PATHS
from my_modules.app.logger import logger
from my_modules.functions import get_ip
from my_modules.app.setup import app
from quart_common.web.security_middleware import register_security_middleware

from quart import session
from datetime import datetime

custom_middleware = register_security_middleware(
  app,
  logger=logger,
  ip_bot_manager=THE_IP_BOT_MANAGER,
  get_ip=get_ip,
  maybe_hacker_fn=maybe_a_hacker,
  skip_paths=SKIP_PATHS,
  skip_path_prefixes=SKIP_PATH_PREFIXES,
)

@app.context_processor
async def inject_context_data():
  user = session.get("user")
  current_year = datetime.now().year

  await logger.debug(f"Inject Context Data | User: {user}, Year: {current_year}")
  return {
    "user": user,
    "year": current_year,
  }
