from fastapi import Request, Response
from sqlalchemy.ext.asyncio import AsyncSession

from api.database import get_session
from api.models.progress_event import ProgressEvent
from api.schemas.progress_event import ProgressEventCreate, ProgressEventRead
from api.services.legacy_compat import meter_legacy_query_param
from hub_core.routers.progress import create_progress_router


async def _meter_progress_workstream_id(
    session: AsyncSession,
    request: Request,
    response: Response,
) -> None:
    await meter_legacy_query_param(
        session=session,
        request=request,
        response=response,
        method="GET",
        route="/progress/",
        replacement_ref="/progress/?workplan_id=<workplan_id>",
    )


router = create_progress_router(
    get_session,
    progress_model=ProgressEvent,
    progress_create_schema=ProgressEventCreate,
    progress_read_schema=ProgressEventRead,
    meter_legacy_workstream_id=_meter_progress_workstream_id,
)

__all__ = ["router"]