export const PermissionFlags = {
	MANAGE_SERVER: 1 << 0,
	MANAGE_CHANNELS: 1 << 1,
	MANAGE_ROLES: 1 << 2,
	MANAGE_MESSAGES: 1 << 3,
	KICK_MEMBERS: 1 << 4,
	BAN_MEMBERS: 1 << 5,
	SEND_MESSAGES: 1 << 6,
	SEND_FILES: 1 << 7,
	ADD_REACTIONS: 1 << 8,
	CONNECT_VOICE: 1 << 9,
	SPEAK: 1 << 10,
	STREAM: 1 << 11,
	MUTE_MEMBERS: 1 << 12,
	DEAFEN_MEMBERS: 1 << 13,
	MOVE_MEMBERS: 1 << 14,
	MENTION_EVERYONE: 1 << 15,
	VIEW_CHANNEL: 1 << 16,
	CREATE_INVITE: 1 << 17,
	CHANGE_NICKNAME: 1 << 18,
	MANAGE_NICKNAMES: 1 << 19,
	MANAGE_EMOJIS: 1 << 20,
	ADMINISTRATOR: 1 << 31,
} as const;

export type PermissionFlag = (typeof PermissionFlags)[keyof typeof PermissionFlags];

export function hasPermission(permissions: number, flag: number): boolean {
	if (permissions & PermissionFlags.ADMINISTRATOR) return true;
	return (permissions & flag) === flag;
}

export function combinePermissions(...flags: number[]): number {
	return flags.reduce((acc, flag) => acc | flag, 0);
}

export const MAX_ROLES_PER_SERVER = 25;
