
from fastapi import APIRouter, Form, HTTPException
from pydantic import BaseModel
from typing import Optional
from app.models import interview_module

router = APIRouter(
    prefix="/goal-skill-t/api/interview",
    tags=["Interview Check"]
)

class EvaluationResponse(BaseModel):
    status: str
    message: str
    id: int

@router.post("/eval", response_model=EvaluationResponse)
async def save_evaluation(
    session_id: str = Form(...),
    rating: int = Form(...),
    advice: Optional[str] = Form(None),
    interviewer_name: Optional[str] = Form(None),
    interview_type: Optional[str] = Form(None) 
):
    try:
        new_id = interview_module.insert_evaluation(
            session_id=session_id,
            rating=rating,
            advice=advice,
            interviewer_name=interviewer_name,
            interview_type=interview_type
        )
        
        return EvaluationResponse(
            status="success",
            message="Evaluation saved successfully.",
            id=new_id
        )

    except Exception as e:
        print(f"[Interview Router Error] {e}")
        raise HTTPException(status_code=500, detail=str(e))
