use axum::{Json, extract::State};
use crank_core::{IssueAgentTokenRequest, IssueOneTimeAgentTokenRequest};

use crate::{error::ApiError, state::AppState};

pub async fn issue_agent_token(
    State(state): State<AppState>,
    Json(payload): Json<IssueAgentTokenRequest>,
) -> Result<Json<serde_json::Value>, ApiError> {
    let response = state.service.issue_agent_token(payload).await?;
    Ok(Json(serde_json::json!(response)))
}

pub async fn issue_one_time_agent_token(
    State(state): State<AppState>,
    Json(payload): Json<IssueOneTimeAgentTokenRequest>,
) -> Result<Json<serde_json::Value>, ApiError> {
    let response = state.service.issue_one_time_agent_token(payload).await?;
    Ok(Json(serde_json::json!(response)))
}
