module Wire.UserSubsystem.HandleBlacklist
  ( isBlacklistedHandle,
  )
where

import Control.Exception (assert)
import Data.Handle (Handle, parseHandle)
import Data.HashSet qualified as HashSet
import Imports

-- | A blacklisted handle cannot be chosen by a (regular) user.
isBlacklistedHandle :: Handle -> Bool
isBlacklistedHandle :: Handle -> Bool
isBlacklistedHandle = (Handle -> HashSet Handle -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet Handle
blacklist)

blacklist :: HashSet Handle
blacklist :: HashSet Handle
blacklist = Bool -> HashSet Handle -> HashSet Handle
forall a. (?callStack::CallStack) => Bool -> a -> a
assert Bool
good ([Handle] -> HashSet Handle
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList (Maybe Handle -> Handle
forall a. (?callStack::CallStack) => Maybe a -> a
fromJust (Maybe Handle -> Handle) -> [Maybe Handle] -> [Handle]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Maybe Handle]
parsed))
  where
    good :: Bool
good = (Maybe Handle -> Bool) -> [Maybe Handle] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Maybe Handle -> Bool
forall a. Maybe a -> Bool
isJust [Maybe Handle]
parsed
    parsed :: [Maybe Handle]
parsed = Text -> Maybe Handle
parseHandle (Text -> Maybe Handle) -> [Text] -> [Maybe Handle]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
raw
    raw :: [Text]
raw =
      [ Text
"account",
        Text
"admin",
        Text
"administrator",
        Text
"all",
        Text
"android",
        Text
"anna",
        Text
"avs",
        Text
"backend",
        Text
"bot",
        Text
"cs",
        Text
"design",
        Text
"dev",
        Text
"developer",
        Text
"development",
        Text
"everyone",
        Text
"help",
        Text
"helpdesk",
        Text
"hr",
        Text
"info",
        Text
"ios",
        Text
"legal",
        Text
"management",
        Text
"news",
        Text
"otto",
        Text
"payment",
        Text
"product",
        Text
"purchase",
        Text
"qa",
        Text
"support",
        Text
"team",
        Text
"user",
        Text
"web",
        Text
"wire",
        Text
"wirebot",
        Text
"wireteam"
      ]