module TD.Data.ChatPhotoSticker
  ( ChatPhotoSticker(..)    
  , defaultChatPhotoSticker 
  ) 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.ChatPhotoStickerType as ChatPhotoStickerType
import qualified TD.Data.BackgroundFill as BackgroundFill

data ChatPhotoSticker
  = ChatPhotoSticker -- ^ Information about the sticker, which was used to create the chat photo. The sticker is shown at the center of the photo and occupies at most 67% of it
    { ChatPhotoSticker -> Maybe ChatPhotoStickerType
_type           :: Maybe ChatPhotoStickerType.ChatPhotoStickerType -- ^ Type of the sticker
    , ChatPhotoSticker -> Maybe BackgroundFill
background_fill :: Maybe BackgroundFill.BackgroundFill             -- ^ The fill to be used as background for the sticker; rotation angle in backgroundFillGradient isn't supported
    }
  deriving (ChatPhotoSticker -> ChatPhotoSticker -> Bool
(ChatPhotoSticker -> ChatPhotoSticker -> Bool)
-> (ChatPhotoSticker -> ChatPhotoSticker -> Bool)
-> Eq ChatPhotoSticker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatPhotoSticker -> ChatPhotoSticker -> Bool
== :: ChatPhotoSticker -> ChatPhotoSticker -> Bool
$c/= :: ChatPhotoSticker -> ChatPhotoSticker -> Bool
/= :: ChatPhotoSticker -> ChatPhotoSticker -> Bool
Eq, Int -> ChatPhotoSticker -> ShowS
[ChatPhotoSticker] -> ShowS
ChatPhotoSticker -> String
(Int -> ChatPhotoSticker -> ShowS)
-> (ChatPhotoSticker -> String)
-> ([ChatPhotoSticker] -> ShowS)
-> Show ChatPhotoSticker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatPhotoSticker -> ShowS
showsPrec :: Int -> ChatPhotoSticker -> ShowS
$cshow :: ChatPhotoSticker -> String
show :: ChatPhotoSticker -> String
$cshowList :: [ChatPhotoSticker] -> ShowS
showList :: [ChatPhotoSticker] -> ShowS
Show)

instance I.ShortShow ChatPhotoSticker where
  shortShow :: ChatPhotoSticker -> String
shortShow ChatPhotoSticker
    { _type :: ChatPhotoSticker -> Maybe ChatPhotoStickerType
_type           = Maybe ChatPhotoStickerType
_type_
    , background_fill :: ChatPhotoSticker -> Maybe BackgroundFill
background_fill = Maybe BackgroundFill
background_fill_
    }
      = String
"ChatPhotoSticker"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_type"           String -> Maybe ChatPhotoStickerType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ChatPhotoStickerType
_type_
        , String
"background_fill" String -> Maybe BackgroundFill -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe BackgroundFill
background_fill_
        ]

instance AT.FromJSON ChatPhotoSticker where
  parseJSON :: Value -> Parser ChatPhotoSticker
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
"chatPhotoSticker" -> Value -> Parser ChatPhotoSticker
parseChatPhotoSticker Value
v
      String
_                  -> Parser ChatPhotoSticker
forall a. Monoid a => a
mempty
    
    where
      parseChatPhotoSticker :: A.Value -> AT.Parser ChatPhotoSticker
      parseChatPhotoSticker :: Value -> Parser ChatPhotoSticker
parseChatPhotoSticker = String
-> (Object -> Parser ChatPhotoSticker)
-> Value
-> Parser ChatPhotoSticker
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPhotoSticker" ((Object -> Parser ChatPhotoSticker)
 -> Value -> Parser ChatPhotoSticker)
-> (Object -> Parser ChatPhotoSticker)
-> Value
-> Parser ChatPhotoSticker
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe ChatPhotoStickerType
_type_           <- Object
o Object -> Key -> Parser (Maybe ChatPhotoStickerType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"type"
        Maybe BackgroundFill
background_fill_ <- Object
o Object -> Key -> Parser (Maybe BackgroundFill)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"background_fill"
        ChatPhotoSticker -> Parser ChatPhotoSticker
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPhotoSticker -> Parser ChatPhotoSticker)
-> ChatPhotoSticker -> Parser ChatPhotoSticker
forall a b. (a -> b) -> a -> b
$ ChatPhotoSticker
          { _type :: Maybe ChatPhotoStickerType
_type           = Maybe ChatPhotoStickerType
_type_
          , background_fill :: Maybe BackgroundFill
background_fill = Maybe BackgroundFill
background_fill_
          }
  parseJSON Value
_ = Parser ChatPhotoSticker
forall a. Monoid a => a
mempty

instance AT.ToJSON ChatPhotoSticker where
  toJSON :: ChatPhotoSticker -> Value
toJSON ChatPhotoSticker
    { _type :: ChatPhotoSticker -> Maybe ChatPhotoStickerType
_type           = Maybe ChatPhotoStickerType
_type_
    , background_fill :: ChatPhotoSticker -> Maybe BackgroundFill
background_fill = Maybe BackgroundFill
background_fill_
    }
      = [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
"chatPhotoSticker"
        , Key
"type"            Key -> Maybe ChatPhotoStickerType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe ChatPhotoStickerType
_type_
        , Key
"background_fill" Key -> Maybe BackgroundFill -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe BackgroundFill
background_fill_
        ]

defaultChatPhotoSticker :: ChatPhotoSticker
defaultChatPhotoSticker :: ChatPhotoSticker
defaultChatPhotoSticker =
  ChatPhotoSticker
    { _type :: Maybe ChatPhotoStickerType
_type           = Maybe ChatPhotoStickerType
forall a. Maybe a
Nothing
    , background_fill :: Maybe BackgroundFill
background_fill = Maybe BackgroundFill
forall a. Maybe a
Nothing
    }