from fastapi import APIRouter, UploadFile, File, Form
from app.services.rembg_service import RembgService

router = APIRouter()

@router.post("/remove-background")
async def remove_background_endpoint(
    file: UploadFile = File(...),
    cloth_name: str = Form("Garment"),
    category: str = Form("Tops"),
    brand: str = Form("MAP"),
    gender: str = Form("Unisex")
):
    """
    Stand-alone Background Removal Studio API endpoint.
    Accepts garment image -> strips background -> returns transparent PNG & mask URL + Decart Lucy VTON prompt.
    """
    contents = await file.read()
    results = RembgService.process_and_save(contents, filename_prefix="rembg")
    suggested_prompt = RembgService.generate_vton_prompt(
        cloth_name=cloth_name,
        category=category,
        brand=brand,
        gender=gender
    )
    return {
        "status": "success",
        "original_url": results["original_url"],
        "cutout_url": results["cutout_url"],
        "mask_url": results["mask_url"],
        "width": results["width"],
        "height": results["height"],
        "suggested_prompt": suggested_prompt
    }
