from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from services.chatbot_service import analyze_user_input, summarize_report

router = APIRouter(tags=["chatbot"])


class AnalyzeRequest(BaseModel):
    user_text: str
    categories: dict = {}


class SummarizeRequest(BaseModel):
    description: str = ""
    type: str = ""
    category: str = ""
    item: str = ""
    location: str = ""
    project: str = ""


@router.post("/chatbot/analyze")
async def chatbot_analyze(req: AnalyzeRequest):
    try:
        result = await analyze_user_input(req.user_text, req.categories)
        return {"success": True, **result}
    except Exception as e:
        raise HTTPException(status_code=500, detail="AI 분석 중 오류가 발생했습니다")


@router.post("/chatbot/summarize")
async def chatbot_summarize(req: SummarizeRequest):
    try:
        result = await summarize_report(req.model_dump())
        return {"success": True, **result}
    except Exception as e:
        raise HTTPException(status_code=500, detail="AI 요약 중 오류가 발생했습니다")
