use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;

use crate::ApiResponse;

#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct TriageIssueQuery {
    pub issue_number: i64,
}

#[utoipa::path(
    get,
    path = "/api/agents/{project}/triage",
    params(
        ("project" = String, Path, description = "Project name"),
        ("issue_number" = i64, Query, description = "Issue number to triage"),
    ),
    responses(
        (status = 200, description = "Issue triage result", body = ApiResponse<service::agent::issue_triage::IssueTriageResponse>),
        (status = 401, description = "Unauthorized"),
        (status = 404, description = "Issue not found"),
    ),
    tag = "Agent"
)]
pub async fn triage_issue(
    service: web::Data<AppService>,
    _session: Session,
    path: web::Path<String>,
    query: web::Query<TriageIssueQuery>,
) -> Result<HttpResponse, crate::error::ApiError> {
    let project_name = path.into_inner();
    let resp = service
        .triage_issue(project_name, query.issue_number)
        .await?;
    Ok(crate::ApiResponse::ok(resp).to_response())
}
