module TD.Data.InputProfileShareTheme
  (InputProfileShareTheme(..)) 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.EmojiType as EmojiType
import qualified Data.Text as T

-- | Describes a theme of the screen for sharing a link to a user or a chat to be set
data InputProfileShareTheme
  = InputProfileShareThemeEmoji -- ^ A theme with emoji placed on a background
    { InputProfileShareTheme -> Maybe [EmojiType]
emojis                 :: Maybe [EmojiType.EmojiType] -- ^ The emoji; 0-6 regular or custom emoji. If empty, then use_default_background must be false
    , InputProfileShareTheme -> Maybe Bool
use_default_background :: Maybe Bool                  -- ^ Pass true to use the default background; otherwise, the backdrop with identifier background_backdrop_id will be used as background
    , InputProfileShareTheme -> Maybe Int
background_backdrop_id :: Maybe Int                   -- ^ Identifier of the backdrop to be used as background; ignored if use_default_background is true. Use getProfileShareThemeBackdrops to get the list of available backdrops
    }
  | InputProfileShareThemeUpgradedGift -- ^ A theme based on an upgraded gift
    { InputProfileShareTheme -> Maybe Text
received_gift_id :: Maybe T.Text -- ^ Identifier of the upgraded gift, which is owned by the user or the chat, for which the theme is set
    }
  deriving (InputProfileShareTheme -> InputProfileShareTheme -> Bool
(InputProfileShareTheme -> InputProfileShareTheme -> Bool)
-> (InputProfileShareTheme -> InputProfileShareTheme -> Bool)
-> Eq InputProfileShareTheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputProfileShareTheme -> InputProfileShareTheme -> Bool
== :: InputProfileShareTheme -> InputProfileShareTheme -> Bool
$c/= :: InputProfileShareTheme -> InputProfileShareTheme -> Bool
/= :: InputProfileShareTheme -> InputProfileShareTheme -> Bool
Eq, Int -> InputProfileShareTheme -> ShowS
[InputProfileShareTheme] -> ShowS
InputProfileShareTheme -> String
(Int -> InputProfileShareTheme -> ShowS)
-> (InputProfileShareTheme -> String)
-> ([InputProfileShareTheme] -> ShowS)
-> Show InputProfileShareTheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputProfileShareTheme -> ShowS
showsPrec :: Int -> InputProfileShareTheme -> ShowS
$cshow :: InputProfileShareTheme -> String
show :: InputProfileShareTheme -> String
$cshowList :: [InputProfileShareTheme] -> ShowS
showList :: [InputProfileShareTheme] -> ShowS
Show)

instance I.ShortShow InputProfileShareTheme where
  shortShow :: InputProfileShareTheme -> String
shortShow InputProfileShareThemeEmoji
    { emojis :: InputProfileShareTheme -> Maybe [EmojiType]
emojis                 = Maybe [EmojiType]
emojis_
    , use_default_background :: InputProfileShareTheme -> Maybe Bool
use_default_background = Maybe Bool
use_default_background_
    , background_backdrop_id :: InputProfileShareTheme -> Maybe Int
background_backdrop_id = Maybe Int
background_backdrop_id_
    }
      = String
"InputProfileShareThemeEmoji"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"emojis"                 String -> Maybe [EmojiType] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [EmojiType]
emojis_
        , String
"use_default_background" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
use_default_background_
        , String
"background_backdrop_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
background_backdrop_id_
        ]
  shortShow InputProfileShareThemeUpgradedGift
    { received_gift_id :: InputProfileShareTheme -> Maybe Text
received_gift_id = Maybe Text
received_gift_id_
    }
      = String
"InputProfileShareThemeUpgradedGift"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"received_gift_id" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
received_gift_id_
        ]

instance AT.FromJSON InputProfileShareTheme where
  parseJSON :: Value -> Parser InputProfileShareTheme
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
"inputProfileShareThemeEmoji"        -> Value -> Parser InputProfileShareTheme
parseInputProfileShareThemeEmoji Value
v
      String
"inputProfileShareThemeUpgradedGift" -> Value -> Parser InputProfileShareTheme
parseInputProfileShareThemeUpgradedGift Value
v
      String
_                                    -> Parser InputProfileShareTheme
forall a. Monoid a => a
mempty
    
    where
      parseInputProfileShareThemeEmoji :: A.Value -> AT.Parser InputProfileShareTheme
      parseInputProfileShareThemeEmoji :: Value -> Parser InputProfileShareTheme
parseInputProfileShareThemeEmoji = String
-> (Object -> Parser InputProfileShareTheme)
-> Value
-> Parser InputProfileShareTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputProfileShareThemeEmoji" ((Object -> Parser InputProfileShareTheme)
 -> Value -> Parser InputProfileShareTheme)
-> (Object -> Parser InputProfileShareTheme)
-> Value
-> Parser InputProfileShareTheme
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [EmojiType]
emojis_                 <- Object
o Object -> Key -> Parser (Maybe [EmojiType])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"emojis"
        Maybe Bool
use_default_background_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"use_default_background"
        Maybe Int
background_backdrop_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"background_backdrop_id"
        InputProfileShareTheme -> Parser InputProfileShareTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputProfileShareTheme -> Parser InputProfileShareTheme)
-> InputProfileShareTheme -> Parser InputProfileShareTheme
forall a b. (a -> b) -> a -> b
$ InputProfileShareThemeEmoji
          { emojis :: Maybe [EmojiType]
emojis                 = Maybe [EmojiType]
emojis_
          , use_default_background :: Maybe Bool
use_default_background = Maybe Bool
use_default_background_
          , background_backdrop_id :: Maybe Int
background_backdrop_id = Maybe Int
background_backdrop_id_
          }
      parseInputProfileShareThemeUpgradedGift :: A.Value -> AT.Parser InputProfileShareTheme
      parseInputProfileShareThemeUpgradedGift :: Value -> Parser InputProfileShareTheme
parseInputProfileShareThemeUpgradedGift = String
-> (Object -> Parser InputProfileShareTheme)
-> Value
-> Parser InputProfileShareTheme
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputProfileShareThemeUpgradedGift" ((Object -> Parser InputProfileShareTheme)
 -> Value -> Parser InputProfileShareTheme)
-> (Object -> Parser InputProfileShareTheme)
-> Value
-> Parser InputProfileShareTheme
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
received_gift_id_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"received_gift_id"
        InputProfileShareTheme -> Parser InputProfileShareTheme
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputProfileShareTheme -> Parser InputProfileShareTheme)
-> InputProfileShareTheme -> Parser InputProfileShareTheme
forall a b. (a -> b) -> a -> b
$ InputProfileShareThemeUpgradedGift
          { received_gift_id :: Maybe Text
received_gift_id = Maybe Text
received_gift_id_
          }
  parseJSON Value
_ = Parser InputProfileShareTheme
forall a. Monoid a => a
mempty

instance AT.ToJSON InputProfileShareTheme where
  toJSON :: InputProfileShareTheme -> Value
toJSON InputProfileShareThemeEmoji
    { emojis :: InputProfileShareTheme -> Maybe [EmojiType]
emojis                 = Maybe [EmojiType]
emojis_
    , use_default_background :: InputProfileShareTheme -> Maybe Bool
use_default_background = Maybe Bool
use_default_background_
    , background_backdrop_id :: InputProfileShareTheme -> Maybe Int
background_backdrop_id = Maybe Int
background_backdrop_id_
    }
      = [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
"inputProfileShareThemeEmoji"
        , Key
"emojis"                 Key -> Maybe [EmojiType] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [EmojiType]
emojis_
        , Key
"use_default_background" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
use_default_background_
        , Key
"background_backdrop_id" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
background_backdrop_id_
        ]
  toJSON InputProfileShareThemeUpgradedGift
    { received_gift_id :: InputProfileShareTheme -> Maybe Text
received_gift_id = Maybe Text
received_gift_id_
    }
      = [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
"inputProfileShareThemeUpgradedGift"
        , Key
"received_gift_id" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
received_gift_id_
        ]