import { Type } from "@sinclair/typebox";
import { FirRouteInput, FirRouteOptions } from "../util/routewrap.ts";
import { getAuthorGames, getReleases } from "../dbal/dbal.ts";

const method = "GET";
const url = "/api/author";

const payloadT = Type.Any();

const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
	const {author} = payload;

	if (typeof author !== "string") {
		return {
			author: null,
			releases: [],
		};
	}
	console.log("author", author);

	const games = await getAuthorGames({author});
	
	return {
		author,
		games,
	}
};

export default {
	method,
	url,
	payloadT,
	handler,
} as const satisfies FirRouteOptions<typeof payloadT>;