from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from services.classification_service import (
    classify_issue,
    summarize_issue,
    classify_and_summarize,
)

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


class ClassifyRequest(BaseModel):
    description: str
    detail_notes: str = ""


class SummarizeRequest(BaseModel):
    description: str
    detail_notes: str = ""
    solution: str = ""


@router.post("/classify")
async def classify(req: ClassifyRequest):
    try:
        result = await classify_issue(req.description, req.detail_notes)
        return {"available": True, **result}
    except Exception as e:
        raise HTTPException(status_code=500, detail="AI 서비스 처리 중 오류가 발생했습니다")


@router.post("/summarize")
async def summarize(req: SummarizeRequest):
    try:
        result = await summarize_issue(req.description, req.detail_notes, req.solution)
        return {"available": True, **result}
    except Exception as e:
        raise HTTPException(status_code=500, detail="AI 서비스 처리 중 오류가 발생했습니다")


@router.post("/classify-and-summarize")
async def classify_and_summarize_endpoint(req: ClassifyRequest):
    try:
        result = await classify_and_summarize(req.description, req.detail_notes)
        return {"available": True, **result}
    except Exception as e:
        raise HTTPException(status_code=500, detail="AI 서비스 처리 중 오류가 발생했습니다")
