import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { GetAccountStore } from '$houdini';

export const load: PageServerLoad = async (event) => {
	const { params, locals, parent } = event;
	const parentData = await parent();

	const accountResult = await new GetAccountStore().fetch({
		event,
		metadata: { cookie: locals.cookie },
		variables: { id: params.account }
	});

	if (!accountResult.data?.account) {
		throw error(404, 'Account not found');
	}

	return {
		...parentData,
		account: accountResult
	};
};
