import { appRouter, t } from "@ibcornelsen/api";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "./constants";

export const createCaller = function (opts: any) {
	// 1. create a caller-function for your router
	const createCaller = t.createCallerFactory(appRouter);
	
	const token = Buffer.from(opts.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME).value ?? "", "utf-8").toString("base64");
	// 2. create a caller using your `Context`
	return createCaller({
		authorization: `Bearer ${token}`,
		ip: "",
		req: opts.request
	});
}