use crate::error::{ApiError, ok_json};
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use service::AppService;
use service::ai::types::AiProviderResponse;
use session::Session;

#[derive(Deserialize, utoipa::IntoParams)]
pub struct ProviderIdPath {
    pub id: uuid::Uuid,
}
#[utoipa::path(
    get, path = "/api/v1/ai/providers",
    responses((status = 200, body = Vec<AiProviderResponse>), (status = 401, description = "Unauthorized")),
    security(("session" = []))
)]
pub async fn list_providers(
    session: Session,
    service: web::Data<AppService>,
) -> Result<HttpResponse, ApiError> {
    ok_json(service.ai_provider_list(&session).await?)
}
#[utoipa::path(
    get, path = "/api/v1/ai/providers/{id}",
    params(("id" = String, Path)), responses((status = 200, body = AiProviderResponse),
        (status = 401, description = "Unauthorized"), (status = 404, description = "Not found")),
    security(("session" = []))
)]
pub async fn get_provider(
    session: Session,
    service: web::Data<AppService>,
    path: web::Path<ProviderIdPath>,
) -> Result<HttpResponse, ApiError> {
    ok_json(
        service
            .ai_provider_get(&session, path.into_inner().id)
            .await?,
    )
}
