module Calamity.Types.Model.Channel.ChannelType
( ChannelType(..) ) where
import Data.Aeson
import Data.Scientific
import GHC.Generics
import TextShow
import qualified TextShow.Generic as TSG
data ChannelType
= GuildTextType
| DMType
| GuildVoiceType
| GroupDMType
| GuildCategoryType
deriving ( Eq, Generic, Show, Enum )
deriving ( TextShow ) via TSG.FromGeneric ChannelType
instance ToJSON ChannelType where
toJSON t = Number $ fromIntegral (fromEnum t)
instance FromJSON ChannelType where
parseJSON = withScientific "ChannelType" $ \n -> case toBoundedInteger n of
Just v -> pure $ toEnum v
Nothing -> fail $ "Invalid ChannelType: " <> show n