import { FSDB_COLLECTION } from '@andyburke/fsdb';
import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
import { by_character } from '@andyburke/fsdb/organizers';

export type USER = {
	id: string;
	username: string;
	permissions: string[];
	timestamps: {
		created: string;
		updated: string;
	};
};

export const USERS = new FSDB_COLLECTION<USER>({
	name: 'users',
	indexers: {
		// email: new FSDB_INDEXER_SYMLINKS<USER>({
		// 	name: 'email',
		// 	field: 'email',
		// 	organize: by_email
		// }),

		username: new FSDB_INDEXER_SYMLINKS<USER>({
			name: 'username',
			field: 'username',
			organize: by_character
		}),

		normalized_username: new FSDB_INDEXER_SYMLINKS<USER>({
			name: 'normalized_username',
			get_values_to_index: (user) => {
				return [user.username.toLowerCase()];
			},
			organize: by_character
		})
	}
});
