from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session

from core.database import get_core_db
from core.security import get_current_user

from . import service
from .dto import CrmMetricsResponse

router = APIRouter()


@router.get("/metrics", response_model=CrmMetricsResponse)
def get_metrics(
    company_id: int = Query(..., description="Company ID"),
    pipeline_id: int | None = Query(None, description="Filtrar embudo del reporte por etapa"),
    current_user: dict = Depends(get_current_user),
    db: Session = Depends(get_core_db),
):
    tenant_id = current_user["tenant_id"]
    return service.get_metrics(db, tenant_id, company_id, pipeline_id)
