from fastapi import APIRouter

from api.deps import get_indexing_service
from api.schemas import IndexRequest, IndexResponse


router = APIRouter(prefix="/api/v1/index", tags=["index"])


@router.post("/rebuild", response_model=IndexResponse)
async def rebuild_index(payload: IndexRequest) -> IndexResponse:
    service = get_indexing_service()
    result = await service.rebuild(
        source_ids=payload.source_ids,
        law_types=payload.law_types,
        reset_collection=payload.reset_collection,
        batch_size=payload.batch_size,
    )
    return IndexResponse(**result)
