"""API endpoints for retrieving information about Albumentations transforms."""

import logging

from fastapi import APIRouter, HTTPException

from src.exceptions import TransformNotFoundError
from src.models.transform import TransformInfo, TransformsResponse
from src.services.transform_service import TransformService

router = APIRouter(tags=["transforms"])
transform_service = TransformService()
logger = logging.getLogger(__name__)


@router.get("/list-transforms")
@router.get("/list_transforms")
async def list_transforms() -> TransformsResponse:
    """List all available transforms grouped by category."""
    transforms = transform_service.get_all_transforms_info()
    return TransformsResponse(
        image_only=transforms["image_only"],
        dual=transforms["dual"],
        transforms_3d=transforms["transforms_3d"],
    )


@router.get("/transform/{transform_name}")
async def get_transform(transform_name: str) -> TransformInfo:
    """Get detailed information about a specific transform."""
    try:
        return transform_service.get_transform_info(transform_name)
    except TransformNotFoundError as e:
        raise HTTPException(status_code=404, detail=str(e)) from e
    except Exception as e:
        logger.exception(f"Error getting transform info for {transform_name}")
        raise HTTPException(status_code=500, detail=str(e)) from e
