from __future__ import annotations

from fastapi import FastAPI


def register_integration_routes(
    app: FastAPI,
    *,
    import_integration_sources,
    fetch_integration_summary,
    fetch_project_metrics,
    fetch_member_metrics,
    fetch_team_metrics,
    fetch_project_breakdowns,
    fetch_payment_source_rows,
    fetch_mh_source_rows,
) -> None:
    @app.post("/api/integration/import")
    def import_integration_data() -> dict[str, object]:
        return import_integration_sources()

    @app.get("/api/integration/summary")
    def integration_summary() -> dict[str, object]:
        return fetch_integration_summary()

    @app.get("/api/integration/projects")
    def integration_projects(limit: int = 500, start_date: str | None = None, end_date: str | None = None) -> dict[str, list[dict[str, object]]]:
        safe_limit = max(1, min(limit, 5000))
        return {"items": fetch_project_metrics(safe_limit, start_date=start_date, end_date=end_date)}

    @app.get("/api/integration/members")
    def integration_members(limit: int = 500, start_date: str | None = None, end_date: str | None = None) -> dict[str, list[dict[str, object]]]:
        safe_limit = max(1, min(limit, 5000))
        return {"items": fetch_member_metrics(safe_limit, start_date=start_date, end_date=end_date)}

    @app.get("/api/integration/teams")
    def integration_teams(start_date: str | None = None, end_date: str | None = None) -> dict[str, list[dict[str, object]]]:
        return {"items": fetch_team_metrics(start_date=start_date, end_date=end_date)}

    @app.get("/api/integration/project-breakdowns")
    def integration_project_breakdowns(start_date: str | None = None, end_date: str | None = None) -> dict[str, list[dict[str, object]]]:
        return fetch_project_breakdowns(start_date=start_date, end_date=end_date)

    @app.get("/api/integration/payment-source")
    def integration_payment_source() -> dict[str, object]:
        return fetch_payment_source_rows()

    @app.get("/api/integration/mh-source")
    def integration_mh_source() -> dict[str, object]:
        return fetch_mh_source_rows()
