{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Channel.ChannelType (ChannelType (..)) where
import qualified Data.Aeson as Aeson
import Data.Scientific
import Optics.TH
import TextShow.TH
data ChannelType
= GuildTextType
| DMType
| GuildVoiceType
| GroupDMType
| GuildCategoryType
| GuildNewsType
| GuildNewsThreadType
| GuildPublicThreadType
| GuildPrivateThreadType
| GuildStageVoiceType
| GuildDirectoryType
| GuildForumType
deriving (ChannelType -> ChannelType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChannelType -> ChannelType -> Bool
$c/= :: ChannelType -> ChannelType -> Bool
== :: ChannelType -> ChannelType -> Bool
$c== :: ChannelType -> ChannelType -> Bool
Eq, Int -> ChannelType -> ShowS
[ChannelType] -> ShowS
ChannelType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChannelType] -> ShowS
$cshowList :: [ChannelType] -> ShowS
show :: ChannelType -> String
$cshow :: ChannelType -> String
showsPrec :: Int -> ChannelType -> ShowS
$cshowsPrec :: Int -> ChannelType -> ShowS
Show, Int -> ChannelType
ChannelType -> Int
ChannelType -> [ChannelType]
ChannelType -> ChannelType
ChannelType -> ChannelType -> [ChannelType]
ChannelType -> ChannelType -> ChannelType -> [ChannelType]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ChannelType -> ChannelType -> ChannelType -> [ChannelType]
$cenumFromThenTo :: ChannelType -> ChannelType -> ChannelType -> [ChannelType]
enumFromTo :: ChannelType -> ChannelType -> [ChannelType]
$cenumFromTo :: ChannelType -> ChannelType -> [ChannelType]
enumFromThen :: ChannelType -> ChannelType -> [ChannelType]
$cenumFromThen :: ChannelType -> ChannelType -> [ChannelType]
enumFrom :: ChannelType -> [ChannelType]
$cenumFrom :: ChannelType -> [ChannelType]
fromEnum :: ChannelType -> Int
$cfromEnum :: ChannelType -> Int
toEnum :: Int -> ChannelType
$ctoEnum :: Int -> ChannelType
pred :: ChannelType -> ChannelType
$cpred :: ChannelType -> ChannelType
succ :: ChannelType -> ChannelType
$csucc :: ChannelType -> ChannelType
Enum)
$(deriveTextShow ''ChannelType)
$(makeFieldLabelsNoPrefix ''ChannelType)
instance Aeson.ToJSON ChannelType where
toJSON :: ChannelType -> Value
toJSON ChannelType
t = forall a. ToJSON a => a -> Value
Aeson.toJSON (forall a. Enum a => a -> Int
fromEnum ChannelType
t)
toEncoding :: ChannelType -> Encoding
toEncoding ChannelType
t = forall a. ToJSON a => a -> Encoding
Aeson.toEncoding (forall a. Enum a => a -> Int
fromEnum ChannelType
t)
instance Aeson.FromJSON ChannelType where
parseJSON :: Value -> Parser ChannelType
parseJSON = forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
Aeson.withScientific String
"ChannelType" forall a b. (a -> b) -> a -> b
$ \Scientific
n -> case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger @Int Scientific
n of
Just Int
v -> case Int
v of
Int
0 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildTextType
Int
1 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
DMType
Int
2 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildVoiceType
Int
3 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GroupDMType
Int
4 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildCategoryType
Int
5 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildNewsType
Int
10 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildNewsThreadType
Int
11 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildPublicThreadType
Int
12 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildPrivateThreadType
Int
13 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildStageVoiceType
Int
14 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildDirectoryType
Int
15 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ChannelType
GuildForumType
Int
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid ChannelType: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
n
Maybe Int
Nothing -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid ChannelType: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Scientific
n