use sfr_types as st;
use crate::response::{CT_APPLICATION_JSON, CT_TEXT_PLAIN};
use axum::body::Body;
use axum::http::status::StatusCode;
use axum::http::Response;
use axum::response::IntoResponse;
#[derive(Debug)]
pub struct SlashCommandResponse(st::SlashCommandResponse);
impl From<st::SlashCommandResponse> for SlashCommandResponse {
fn from(r: st::SlashCommandResponse) -> Self {
Self(r)
}
}
impl IntoResponse for SlashCommandResponse {
fn into_response(self) -> Response<Body> {
match self.0 {
st::SlashCommandResponse::Empty => return ([CT_TEXT_PLAIN], "").into_response(),
st::SlashCommandResponse::String(s) => return ([CT_TEXT_PLAIN], s).into_response(),
st::SlashCommandResponse::Layouts(_)
| st::SlashCommandResponse::LayoutsInChannel(_) => {}
}
let body = match serde_json::to_string(&self.0) {
Ok(body) => body,
Err(e) => {
tracing::warn!("failed to serialise to build layouts: {e:?}");
return (StatusCode::INTERNAL_SERVER_ERROR, "").into_response();
}
};
tracing::trace!("SlashCommandResponse::into_response: body = {body}");
([CT_APPLICATION_JSON], body).into_response()
}
}