use axum::extract::State;
use std::sync::Arc;

use validator::Validate;

use infra::{
    core::AppState,
    extract::json::Json,
    status::{ApiResult, api_err::ApiErr},
};

use crate::service::{
    self,
    greeter::{ReqHello, RespHello},
};

pub async fn hello(State(ctx): State<Arc<AppState>>, Json(req): Json<ReqHello>) -> ApiResult<RespHello> {
    if let Err(e) = req.validate() {
        return Err(ApiErr::Params(e.to_string()));
    }
    service::greeter::hello(&ctx, req).await
}
