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

-- | Contains full information about sticker type
data StickerFullType
  = StickerFullTypeRegular -- ^ The sticker is a regular sticker
    { StickerFullType -> Maybe File
premium_animation :: Maybe File.File -- ^ Premium animation of the sticker; may be null. If present, only Telegram Premium users can use the sticker
    }
  | StickerFullTypeMask -- ^ The sticker is a mask in WEBP format to be placed on photos or videos
    { StickerFullType -> Maybe MaskPosition
mask_position :: Maybe MaskPosition.MaskPosition -- ^ Position where the mask is placed; may be null
    }
  | StickerFullTypeCustomEmoji -- ^ The sticker is a custom emoji to be used inside message text and caption. Currently, only Telegram Premium users can use custom emoji
    { StickerFullType -> Maybe Int
custom_emoji_id  :: Maybe Int  -- ^ Identifier of the custom emoji
    , StickerFullType -> Maybe Bool
needs_repainting :: Maybe Bool -- ^ True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places
    }
  deriving (StickerFullType -> StickerFullType -> Bool
(StickerFullType -> StickerFullType -> Bool)
-> (StickerFullType -> StickerFullType -> Bool)
-> Eq StickerFullType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StickerFullType -> StickerFullType -> Bool
== :: StickerFullType -> StickerFullType -> Bool
$c/= :: StickerFullType -> StickerFullType -> Bool
/= :: StickerFullType -> StickerFullType -> Bool
Eq, Int -> StickerFullType -> ShowS
[StickerFullType] -> ShowS
StickerFullType -> String
(Int -> StickerFullType -> ShowS)
-> (StickerFullType -> String)
-> ([StickerFullType] -> ShowS)
-> Show StickerFullType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StickerFullType -> ShowS
showsPrec :: Int -> StickerFullType -> ShowS
$cshow :: StickerFullType -> String
show :: StickerFullType -> String
$cshowList :: [StickerFullType] -> ShowS
showList :: [StickerFullType] -> ShowS
Show)

instance I.ShortShow StickerFullType where
  shortShow :: StickerFullType -> String
shortShow StickerFullTypeRegular
    { premium_animation :: StickerFullType -> Maybe File
premium_animation = Maybe File
premium_animation_
    }
      = String
"StickerFullTypeRegular"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"premium_animation" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
premium_animation_
        ]
  shortShow StickerFullTypeMask
    { mask_position :: StickerFullType -> Maybe MaskPosition
mask_position = Maybe MaskPosition
mask_position_
    }
      = String
"StickerFullTypeMask"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"mask_position" String -> Maybe MaskPosition -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MaskPosition
mask_position_
        ]
  shortShow StickerFullTypeCustomEmoji
    { custom_emoji_id :: StickerFullType -> Maybe Int
custom_emoji_id  = Maybe Int
custom_emoji_id_
    , needs_repainting :: StickerFullType -> Maybe Bool
needs_repainting = Maybe Bool
needs_repainting_
    }
      = String
"StickerFullTypeCustomEmoji"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"custom_emoji_id"  String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
custom_emoji_id_
        , String
"needs_repainting" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
needs_repainting_
        ]

instance AT.FromJSON StickerFullType where
  parseJSON :: Value -> Parser StickerFullType
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
"stickerFullTypeRegular"     -> Value -> Parser StickerFullType
parseStickerFullTypeRegular Value
v
      String
"stickerFullTypeMask"        -> Value -> Parser StickerFullType
parseStickerFullTypeMask Value
v
      String
"stickerFullTypeCustomEmoji" -> Value -> Parser StickerFullType
parseStickerFullTypeCustomEmoji Value
v
      String
_                            -> Parser StickerFullType
forall a. Monoid a => a
mempty
    
    where
      parseStickerFullTypeRegular :: A.Value -> AT.Parser StickerFullType
      parseStickerFullTypeRegular :: Value -> Parser StickerFullType
parseStickerFullTypeRegular = String
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StickerFullTypeRegular" ((Object -> Parser StickerFullType)
 -> Value -> Parser StickerFullType)
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe File
premium_animation_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"premium_animation"
        StickerFullType -> Parser StickerFullType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StickerFullType -> Parser StickerFullType)
-> StickerFullType -> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ StickerFullTypeRegular
          { premium_animation :: Maybe File
premium_animation = Maybe File
premium_animation_
          }
      parseStickerFullTypeMask :: A.Value -> AT.Parser StickerFullType
      parseStickerFullTypeMask :: Value -> Parser StickerFullType
parseStickerFullTypeMask = String
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StickerFullTypeMask" ((Object -> Parser StickerFullType)
 -> Value -> Parser StickerFullType)
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe MaskPosition
mask_position_ <- Object
o Object -> Key -> Parser (Maybe MaskPosition)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"mask_position"
        StickerFullType -> Parser StickerFullType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StickerFullType -> Parser StickerFullType)
-> StickerFullType -> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ StickerFullTypeMask
          { mask_position :: Maybe MaskPosition
mask_position = Maybe MaskPosition
mask_position_
          }
      parseStickerFullTypeCustomEmoji :: A.Value -> AT.Parser StickerFullType
      parseStickerFullTypeCustomEmoji :: Value -> Parser StickerFullType
parseStickerFullTypeCustomEmoji = String
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StickerFullTypeCustomEmoji" ((Object -> Parser StickerFullType)
 -> Value -> Parser StickerFullType)
-> (Object -> Parser StickerFullType)
-> Value
-> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
custom_emoji_id_  <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"custom_emoji_id"
        Maybe Bool
needs_repainting_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"needs_repainting"
        StickerFullType -> Parser StickerFullType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StickerFullType -> Parser StickerFullType)
-> StickerFullType -> Parser StickerFullType
forall a b. (a -> b) -> a -> b
$ StickerFullTypeCustomEmoji
          { custom_emoji_id :: Maybe Int
custom_emoji_id  = Maybe Int
custom_emoji_id_
          , needs_repainting :: Maybe Bool
needs_repainting = Maybe Bool
needs_repainting_
          }
  parseJSON Value
_ = Parser StickerFullType
forall a. Monoid a => a
mempty