import { authContextGenerator, authPluginGenerator, authRolesGenerator, pothosAuthGenerator, prismaAuthorizerUtilsGenerator, userSessionTypesGenerator, } from '@baseplate-dev/fastify-generators';
import { appCompilerSpec, backendAppEntryType, createPlatformPluginExport, PluginUtils, webAppEntryType, } from '@baseplate-dev/project-builder-lib';
import { authErrorsGenerator, authIdentifyGenerator, } from '@baseplate-dev/react-generators';
export default createPlatformPluginExport({
    dependencies: {
        appCompiler: appCompilerSpec,
    },
    exports: {},
    initialize: ({ appCompiler }, { pluginKey }) => {
        // register backend compiler
        appCompiler.registerAppCompiler({
            pluginKey,
            appType: backendAppEntryType,
            compile: ({ projectDefinition, appCompiler }) => {
                const auth = PluginUtils.configByKeyOrThrow(projectDefinition, pluginKey);
                appCompiler.addChildrenToFeature(auth.authFeatureRef, {
                    authContext: authContextGenerator({}),
                    authPlugin: authPluginGenerator({}),
                    authRoles: authRolesGenerator({
                        roles: auth.roles.map((r) => ({
                            name: r.name,
                            comment: r.comment,
                            builtIn: r.builtIn,
                        })),
                    }),
                    userSessionTypes: userSessionTypesGenerator({}),
                });
                appCompiler.addRootChildren({
                    pothosAuth: pothosAuthGenerator({}),
                    authorizerUtils: prismaAuthorizerUtilsGenerator({}),
                });
            },
        });
        // register web compiler
        appCompiler.registerAppCompiler({
            pluginKey,
            appType: webAppEntryType,
            compile: ({ appCompiler }) => {
                appCompiler.addRootChildren({
                    authIdentify: authIdentifyGenerator({}),
                    authErrors: authErrorsGenerator({}),
                });
            },
        });
        return {};
    },
});
//# sourceMappingURL=node.js.map