module TD.Data.StickerFormat
  (StickerFormat(..)) where

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

-- | Describes format of a sticker
data StickerFormat
  = StickerFormatWebp -- ^ The sticker is an image in WEBP format
  | StickerFormatTgs -- ^ The sticker is an animation in TGS format
  | StickerFormatWebm -- ^ The sticker is a video in WEBM format
  deriving (StickerFormat -> StickerFormat -> Bool
(StickerFormat -> StickerFormat -> Bool)
-> (StickerFormat -> StickerFormat -> Bool) -> Eq StickerFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StickerFormat -> StickerFormat -> Bool
== :: StickerFormat -> StickerFormat -> Bool
$c/= :: StickerFormat -> StickerFormat -> Bool
/= :: StickerFormat -> StickerFormat -> Bool
Eq, Int -> StickerFormat -> ShowS
[StickerFormat] -> ShowS
StickerFormat -> String
(Int -> StickerFormat -> ShowS)
-> (StickerFormat -> String)
-> ([StickerFormat] -> ShowS)
-> Show StickerFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StickerFormat -> ShowS
showsPrec :: Int -> StickerFormat -> ShowS
$cshow :: StickerFormat -> String
show :: StickerFormat -> String
$cshowList :: [StickerFormat] -> ShowS
showList :: [StickerFormat] -> ShowS
Show)

instance I.ShortShow StickerFormat where
  shortShow :: StickerFormat -> String
shortShow StickerFormat
StickerFormatWebp
      = String
"StickerFormatWebp"
  shortShow StickerFormat
StickerFormatTgs
      = String
"StickerFormatTgs"
  shortShow StickerFormat
StickerFormatWebm
      = String
"StickerFormatWebm"

instance AT.FromJSON StickerFormat where
  parseJSON :: Value -> Parser StickerFormat
parseJSON (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
"stickerFormatWebp" -> StickerFormat -> Parser StickerFormat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StickerFormat
StickerFormatWebp
      String
"stickerFormatTgs"  -> StickerFormat -> Parser StickerFormat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StickerFormat
StickerFormatTgs
      String
"stickerFormatWebm" -> StickerFormat -> Parser StickerFormat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StickerFormat
StickerFormatWebm
      String
_                   -> Parser StickerFormat
forall a. Monoid a => a
mempty
    
  parseJSON Value
_ = Parser StickerFormat
forall a. Monoid a => a
mempty

instance AT.ToJSON StickerFormat where
  toJSON :: StickerFormat -> Value
toJSON StickerFormat
StickerFormatWebp
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"stickerFormatWebp"
        ]
  toJSON StickerFormat
StickerFormatTgs
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"stickerFormatTgs"
        ]
  toJSON StickerFormat
StickerFormatWebm
      = [Pair] -> Value
A.object
        [ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"stickerFormatWebm"
        ]