"""Shared FastAPI dependencies: engine access + bearer auth.

Auth is resolved indirectly through app.state so tests can inject a stub and
the hosted offering can swap BearerAuth for a licenses/activations lookup
without touching any route signature.
"""
from __future__ import annotations

from fastapi import Depends, Request

from .auth import Principal
from .config import ServerConfig
from .engine import EngineHost
from .jobs import JobRunner, JobStore


def get_config(request: Request) -> ServerConfig:
    return request.app.state.config


def get_engine(request: Request) -> EngineHost:
    return request.app.state.engine


def get_store(request: Request) -> JobStore:
    return request.app.state.store


def get_runner(request: Request) -> JobRunner:
    return request.app.state.runner


async def require_auth(request: Request) -> Principal:
    return await request.app.state.auth(request)


AuthDep = Depends(require_auth)
