module TD.Data.AnimatedEmoji
  (AnimatedEmoji(..)) 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.Sticker as Sticker
import qualified TD.Data.File as File

data AnimatedEmoji
  = AnimatedEmoji -- ^ Describes an animated or custom representation of an emoji
    { AnimatedEmoji -> Maybe Sticker
sticker          :: Maybe Sticker.Sticker -- ^ Sticker for the emoji; may be null if yet unknown for a custom emoji. If the sticker is a custom emoji, then it can have arbitrary format
    , AnimatedEmoji -> Maybe Int
sticker_width    :: Maybe Int             -- ^ Expected width of the sticker, which can be used if the sticker is null
    , AnimatedEmoji -> Maybe Int
sticker_height   :: Maybe Int             -- ^ Expected height of the sticker, which can be used if the sticker is null
    , AnimatedEmoji -> Maybe Int
fitzpatrick_type :: Maybe Int             -- ^ Emoji modifier fitzpatrick type; 0-6; 0 if none
    , AnimatedEmoji -> Maybe File
sound            :: Maybe File.File       -- ^ File containing the sound to be played when the sticker is clicked; may be null. The sound is encoded with the Opus codec, and stored inside an OGG container
    }
  deriving (AnimatedEmoji -> AnimatedEmoji -> Bool
(AnimatedEmoji -> AnimatedEmoji -> Bool)
-> (AnimatedEmoji -> AnimatedEmoji -> Bool) -> Eq AnimatedEmoji
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AnimatedEmoji -> AnimatedEmoji -> Bool
== :: AnimatedEmoji -> AnimatedEmoji -> Bool
$c/= :: AnimatedEmoji -> AnimatedEmoji -> Bool
/= :: AnimatedEmoji -> AnimatedEmoji -> Bool
Eq, Int -> AnimatedEmoji -> ShowS
[AnimatedEmoji] -> ShowS
AnimatedEmoji -> String
(Int -> AnimatedEmoji -> ShowS)
-> (AnimatedEmoji -> String)
-> ([AnimatedEmoji] -> ShowS)
-> Show AnimatedEmoji
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AnimatedEmoji -> ShowS
showsPrec :: Int -> AnimatedEmoji -> ShowS
$cshow :: AnimatedEmoji -> String
show :: AnimatedEmoji -> String
$cshowList :: [AnimatedEmoji] -> ShowS
showList :: [AnimatedEmoji] -> ShowS
Show)

instance I.ShortShow AnimatedEmoji where
  shortShow :: AnimatedEmoji -> String
shortShow AnimatedEmoji
    { sticker :: AnimatedEmoji -> Maybe Sticker
sticker          = Maybe Sticker
sticker_
    , sticker_width :: AnimatedEmoji -> Maybe Int
sticker_width    = Maybe Int
sticker_width_
    , sticker_height :: AnimatedEmoji -> Maybe Int
sticker_height   = Maybe Int
sticker_height_
    , fitzpatrick_type :: AnimatedEmoji -> Maybe Int
fitzpatrick_type = Maybe Int
fitzpatrick_type_
    , sound :: AnimatedEmoji -> Maybe File
sound            = Maybe File
sound_
    }
      = String
"AnimatedEmoji"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"sticker"          String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
sticker_
        , String
"sticker_width"    String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sticker_width_
        , String
"sticker_height"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
sticker_height_
        , String
"fitzpatrick_type" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
fitzpatrick_type_
        , String
"sound"            String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
sound_
        ]

instance AT.FromJSON AnimatedEmoji where
  parseJSON :: Value -> Parser AnimatedEmoji
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
"animatedEmoji" -> Value -> Parser AnimatedEmoji
parseAnimatedEmoji Value
v
      String
_               -> Parser AnimatedEmoji
forall a. Monoid a => a
mempty
    
    where
      parseAnimatedEmoji :: A.Value -> AT.Parser AnimatedEmoji
      parseAnimatedEmoji :: Value -> Parser AnimatedEmoji
parseAnimatedEmoji = String
-> (Object -> Parser AnimatedEmoji)
-> Value
-> Parser AnimatedEmoji
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AnimatedEmoji" ((Object -> Parser AnimatedEmoji) -> Value -> Parser AnimatedEmoji)
-> (Object -> Parser AnimatedEmoji)
-> Value
-> Parser AnimatedEmoji
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Sticker
sticker_          <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker"
        Maybe Int
sticker_width_    <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker_width"
        Maybe Int
sticker_height_   <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sticker_height"
        Maybe Int
fitzpatrick_type_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"fitzpatrick_type"
        Maybe File
sound_            <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"sound"
        AnimatedEmoji -> Parser AnimatedEmoji
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AnimatedEmoji -> Parser AnimatedEmoji)
-> AnimatedEmoji -> Parser AnimatedEmoji
forall a b. (a -> b) -> a -> b
$ AnimatedEmoji
          { sticker :: Maybe Sticker
sticker          = Maybe Sticker
sticker_
          , sticker_width :: Maybe Int
sticker_width    = Maybe Int
sticker_width_
          , sticker_height :: Maybe Int
sticker_height   = Maybe Int
sticker_height_
          , fitzpatrick_type :: Maybe Int
fitzpatrick_type = Maybe Int
fitzpatrick_type_
          , sound :: Maybe File
sound            = Maybe File
sound_
          }
  parseJSON Value
_ = Parser AnimatedEmoji
forall a. Monoid a => a
mempty