from fastapi import APIRouter

from app.services.raster_service import load_bands
from app.services.ndvi_service import calculate_ndvi
from app.services.biomass_service import (
    estimate_agb,
    estimate_bgb
)

router = APIRouter(tags=["Analysis"])


@router.post("/analyze")
async def analyze(image_path: str):

    bands = load_bands(image_path)

    ndvi = calculate_ndvi(
        bands["red"],
        bands["nir"]
    )

    agb = estimate_agb(ndvi)

    bgb = estimate_bgb(agb)

    return {
        "mean_ndvi": float(ndvi.mean()),
        "max_ndvi": float(ndvi.max()),
        "min_ndvi": float(ndvi.min()),
        "mean_agb": float(agb.mean()),
        "mean_bgb": float(bgb.mean())
    }