use std::error::Error;
use std::pin::Pin;

pub use atelier::rusqlite_thread_pool::PoolSender as DbS;
pub type Request = axum::extract::Request;
pub struct RequestCtx {
	pub dbs: DbS,
	pub path_params: atelier::router::PathParams,
}

pub type Response = axum::response::Response;
pub type Handler = Box<
	dyn Fn(
			Request,
			RequestCtx,
		) -> Pin<Box<dyn Future<Output = Response> + Send + 'static>>
		+ Send
		+ Sync
		+ 'static,
>;
pub type Router = atelier::router::Router<Handler>;
pub type AnyError = Box<dyn Error + Send + Sync + 'static>;
pub type Result<T> = core::result::Result<T, AnyError>;

pub use axum::response::IntoResponse;
pub enum HandlerError {
	InternalServerError(AnyError),
}
impl<E> From<E> for HandlerError
where
	E: Error + Send + Sync + 'static,
{
	fn from(v: E) -> Self {
		Self::InternalServerError(Box::new(v))
	}
}
impl IntoResponse for HandlerError {
	fn into_response(self) -> Response {
		"".into_response()
	}
}

pub type HandlerResult<T: IntoResponse> = core::result::Result<T, HandlerError>;

pub use crate::templates::{template_fn, Template, TemplateFn};
pub use core::fmt::{Display, Formatter};
pub type FmtResult = core::fmt::Result;
pub use axum::response::Html;
