package permissions

// Permission bitflags.
const (
	VIEW_CHANNEL          int64 = 1 << 0
	SEND_MESSAGES         int64 = 1 << 1
	MANAGE_MESSAGES       int64 = 1 << 2
	KICK_MEMBERS          int64 = 1 << 3
	BAN_MEMBERS           int64 = 1 << 4
	MANAGE_SERVER         int64 = 1 << 5
	MANAGE_CHANNELS       int64 = 1 << 6
	ADMINISTRATOR         int64 = 1 << 7
	CONNECT_VOICE         int64 = 1 << 8
	SPEAK_VOICE           int64 = 1 << 9
	SHARE_SCREEN          int64 = 1 << 10
	MUTE_MEMBERS          int64 = 1 << 11
	CREATE_INSTANT_INVITE int64 = 1 << 12
	CHANGE_NICKNAME       int64 = 1 << 13
	MANAGE_NICKNAMES      int64 = 1 << 14
	MANAGE_ROLES          int64 = 1 << 15
	MANAGE_WEBHOOKS       int64 = 1 << 16
	EMBED_LINKS           int64 = 1 << 17
	ATTACH_FILES          int64 = 1 << 18
	ADD_REACTIONS         int64 = 1 << 19
	USE_EXTERNAL_EMOJIS   int64 = 1 << 20
	MENTION_EVERYONE      int64 = 1 << 21
)

// AllPermissionLabels maps flags to human-friendly names.
var AllPermissionLabels = []struct {
	Key  string
	Flag int64
}{
	{"VIEW_CHANNEL", VIEW_CHANNEL},
	{"SEND_MESSAGES", SEND_MESSAGES},
	{"MANAGE_MESSAGES", MANAGE_MESSAGES},
	{"KICK_MEMBERS", KICK_MEMBERS},
	{"BAN_MEMBERS", BAN_MEMBERS},
	{"MANAGE_SERVER", MANAGE_SERVER},
	{"MANAGE_CHANNELS", MANAGE_CHANNELS},
	{"ADMINISTRATOR", ADMINISTRATOR},
	{"CONNECT_VOICE", CONNECT_VOICE},
	{"SPEAK_VOICE", SPEAK_VOICE},
	{"SHARE_SCREEN", SHARE_SCREEN},
	{"MUTE_MEMBERS", MUTE_MEMBERS},
	{"CREATE_INSTANT_INVITE", CREATE_INSTANT_INVITE},
	{"CHANGE_NICKNAME", CHANGE_NICKNAME},
	{"MANAGE_NICKNAMES", MANAGE_NICKNAMES},
	{"MANAGE_ROLES", MANAGE_ROLES},
	{"MANAGE_WEBHOOKS", MANAGE_WEBHOOKS},
	{"EMBED_LINKS", EMBED_LINKS},
	{"ATTACH_FILES", ATTACH_FILES},
	{"ADD_REACTIONS", ADD_REACTIONS},
	{"USE_EXTERNAL_EMOJIS", USE_EXTERNAL_EMOJIS},
	{"MENTION_EVERYONE", MENTION_EVERYONE},
}

// DefaultEveryonePermissions is granted to the @everyone role when a server is created.
// VIEW_CHANNEL | SEND_MESSAGES | CONNECT_VOICE | SPEAK_VOICE | SHARE_SCREEN | CREATE_INSTANT_INVITE | EMBED_LINKS | ATTACH_FILES | ADD_REACTIONS = bits 0,1,8,9,10,12,17,18,19.
const DefaultEveryonePermissions int64 = VIEW_CHANNEL | SEND_MESSAGES | CONNECT_VOICE | SPEAK_VOICE | SHARE_SCREEN | CREATE_INSTANT_INVITE | EMBED_LINKS | ATTACH_FILES | ADD_REACTIONS

// Has reports whether the permission set contains the given permission bits.
func Has(permissions int64, perm int64) bool {
	return permissions&perm == perm
}

// Add returns permissions with the given bits set.
func Add(permissions int64, perm int64) int64 {
	return permissions | perm
}

// Remove returns permissions with the given bits cleared.
func Remove(permissions int64, perm int64) int64 {
	return permissions &^ perm
}
