import { Plugin } from '@nuxt/types';
import { ProjectSettingsRegistry } from "~/registry/projectSettings";
import { ProjectViewRegistry } from "~/registry/projectViews";
import { TaskActionRegistry } from "~/registry/taskActions";
import { TaskSectionRegistry } from "~/registry/taskSections";
import { UserSettingsRegistry } from '~/registry/userSettings';

export interface Registries {
	projectSettings: ProjectSettingsRegistry,
	projectViews: ProjectViewRegistry,
	userSettings: UserSettingsRegistry,
	taskActions: TaskActionRegistry,
	taskSections: TaskSectionRegistry
}

const plugin: Plugin = (context, inject) => {

	// Registry definition
	const registries: Registries = {
		projectSettings: new ProjectSettingsRegistry(context),
		projectViews: new ProjectViewRegistry(context),
		userSettings: new UserSettingsRegistry(context),
		taskActions: new TaskActionRegistry(context),
		taskSections: new TaskSectionRegistry(context)
	};

	// TODO Temporary until extension system is implemented
	for(const registry of Object.values(registries)) {
		registry.complete();
	}

	inject('registries', registries);
};

export default plugin;