{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Channel.Reaction (Reaction (..)) where
import Calamity.Internal.Utils (CalamityToJSON (..), CalamityToJSON' (toPairs), (.=))
import Calamity.Types.Model.Guild.Emoji
import Data.Aeson ((.:))
import Data.Aeson qualified as Aeson
import Optics.TH
import TextShow.TH
data Reaction = Reaction
{ Reaction -> Integer
count :: Integer
, Reaction -> Bool
me :: Bool
, Reaction -> RawEmoji
emoji :: RawEmoji
}
deriving (Reaction -> Reaction -> Bool
(Reaction -> Reaction -> Bool)
-> (Reaction -> Reaction -> Bool) -> Eq Reaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Reaction -> Reaction -> Bool
== :: Reaction -> Reaction -> Bool
$c/= :: Reaction -> Reaction -> Bool
/= :: Reaction -> Reaction -> Bool
Eq, Int -> Reaction -> ShowS
[Reaction] -> ShowS
Reaction -> String
(Int -> Reaction -> ShowS)
-> (Reaction -> String) -> ([Reaction] -> ShowS) -> Show Reaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Reaction -> ShowS
showsPrec :: Int -> Reaction -> ShowS
$cshow :: Reaction -> String
show :: Reaction -> String
$cshowList :: [Reaction] -> ShowS
showList :: [Reaction] -> ShowS
Show)
deriving ([Reaction] -> Value
[Reaction] -> Encoding
Reaction -> Value
Reaction -> Encoding
(Reaction -> Value)
-> (Reaction -> Encoding)
-> ([Reaction] -> Value)
-> ([Reaction] -> Encoding)
-> ToJSON Reaction
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: Reaction -> Value
toJSON :: Reaction -> Value
$ctoEncoding :: Reaction -> Encoding
toEncoding :: Reaction -> Encoding
$ctoJSONList :: [Reaction] -> Value
toJSONList :: [Reaction] -> Value
$ctoEncodingList :: [Reaction] -> Encoding
toEncodingList :: [Reaction] -> Encoding
Aeson.ToJSON) via CalamityToJSON Reaction
instance CalamityToJSON' Reaction where
toPairs :: forall kv. KeyValue kv => Reaction -> [Maybe kv]
toPairs Reaction {Bool
Integer
RawEmoji
$sel:count:Reaction :: Reaction -> Integer
$sel:me:Reaction :: Reaction -> Bool
$sel:emoji:Reaction :: Reaction -> RawEmoji
count :: Integer
me :: Bool
emoji :: RawEmoji
..} =
[ Key
"count" Key -> Integer -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Integer
count
, Key
"me" Key -> Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Bool
me
, Key
"emoj" Key -> RawEmoji -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= RawEmoji
emoji
]
instance Aeson.FromJSON Reaction where
parseJSON :: Value -> Parser Reaction
parseJSON = String -> (Object -> Parser Reaction) -> Value -> Parser Reaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Reaction" ((Object -> Parser Reaction) -> Value -> Parser Reaction)
-> (Object -> Parser Reaction) -> Value -> Parser Reaction
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Integer -> Bool -> RawEmoji -> Reaction
Reaction
(Integer -> Bool -> RawEmoji -> Reaction)
-> Parser Integer -> Parser (Bool -> RawEmoji -> Reaction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Integer
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"count"
Parser (Bool -> RawEmoji -> Reaction)
-> Parser Bool -> Parser (RawEmoji -> Reaction)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"me"
Parser (RawEmoji -> Reaction) -> Parser RawEmoji -> Parser Reaction
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser RawEmoji
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"emoji"
$(deriveTextShow ''Reaction)
$(makeFieldLabelsNoPrefix ''Reaction)