import { IResponse, Status, statusMessage } from "@autoplex/restful";
import { FastifyReply } from "fastify";

/**
 * Re-export the RESTful response info for convenience
 */
export { IResponse, Status, statusMessage };

/**
 *  Respond to a request
 */
export function respond<T = any>(reply: FastifyReply, status: Status, result?: T) {
	let response: IResponse<any> = { status: statusMessage(status) };
	if (result !== undefined) {
		response.result = result;
	}
	reply.status(status);
	reply.send(response);
}
