module TD.Data.EmojiKeywords
  (EmojiKeywords(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.EmojiKeyword as EmojiKeyword

data EmojiKeywords
  = EmojiKeywords -- ^ Represents a list of emojis with their keywords
    { EmojiKeywords -> Maybe [EmojiKeyword]
emoji_keywords :: Maybe [EmojiKeyword.EmojiKeyword] -- ^ List of emojis with their keywords
    }
  deriving (EmojiKeywords -> EmojiKeywords -> Bool
(EmojiKeywords -> EmojiKeywords -> Bool)
-> (EmojiKeywords -> EmojiKeywords -> Bool) -> Eq EmojiKeywords
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmojiKeywords -> EmojiKeywords -> Bool
== :: EmojiKeywords -> EmojiKeywords -> Bool
$c/= :: EmojiKeywords -> EmojiKeywords -> Bool
/= :: EmojiKeywords -> EmojiKeywords -> Bool
Eq, Int -> EmojiKeywords -> ShowS
[EmojiKeywords] -> ShowS
EmojiKeywords -> String
(Int -> EmojiKeywords -> ShowS)
-> (EmojiKeywords -> String)
-> ([EmojiKeywords] -> ShowS)
-> Show EmojiKeywords
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmojiKeywords -> ShowS
showsPrec :: Int -> EmojiKeywords -> ShowS
$cshow :: EmojiKeywords -> String
show :: EmojiKeywords -> String
$cshowList :: [EmojiKeywords] -> ShowS
showList :: [EmojiKeywords] -> ShowS
Show)

instance I.ShortShow EmojiKeywords where
  shortShow :: EmojiKeywords -> String
shortShow EmojiKeywords
    { emoji_keywords :: EmojiKeywords -> Maybe [EmojiKeyword]
emoji_keywords = Maybe [EmojiKeyword]
emoji_keywords_
    }
      = String
"EmojiKeywords"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"emoji_keywords" String -> Maybe [EmojiKeyword] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [EmojiKeyword]
emoji_keywords_
        ]

instance AT.FromJSON EmojiKeywords where
  parseJSON :: Value -> Parser EmojiKeywords
parseJSON v :: Value
v@(AT.Object Object
obj) = do
    String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String

    case String
t of
      String
"emojiKeywords" -> Value -> Parser EmojiKeywords
parseEmojiKeywords Value
v
      String
_               -> Parser EmojiKeywords
forall a. Monoid a => a
mempty
    
    where
      parseEmojiKeywords :: A.Value -> AT.Parser EmojiKeywords
      parseEmojiKeywords :: Value -> Parser EmojiKeywords
parseEmojiKeywords = String
-> (Object -> Parser EmojiKeywords)
-> Value
-> Parser EmojiKeywords
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmojiKeywords" ((Object -> Parser EmojiKeywords) -> Value -> Parser EmojiKeywords)
-> (Object -> Parser EmojiKeywords)
-> Value
-> Parser EmojiKeywords
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [EmojiKeyword]
emoji_keywords_ <- Object
o Object -> Key -> Parser (Maybe [EmojiKeyword])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"emoji_keywords"
        EmojiKeywords -> Parser EmojiKeywords
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmojiKeywords -> Parser EmojiKeywords)
-> EmojiKeywords -> Parser EmojiKeywords
forall a b. (a -> b) -> a -> b
$ EmojiKeywords
          { emoji_keywords :: Maybe [EmojiKeyword]
emoji_keywords = Maybe [EmojiKeyword]
emoji_keywords_
          }
  parseJSON Value
_ = Parser EmojiKeywords
forall a. Monoid a => a
mempty