module TD.Data.SuggestedAction
  (SuggestedAction(..)) where

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

-- | Describes an action suggested to the current user
data SuggestedAction
  = SuggestedActionEnableArchiveAndMuteNewChats -- ^ Suggests the user to enable archive_and_mute_new_chats_from_unknown_users setting in archiveChatListSettings
  | SuggestedActionCheckPassword -- ^ Suggests the user to check whether they still remember their 2-step verification password
  | SuggestedActionCheckPhoneNumber -- ^ Suggests the user to check whether authorization phone number is correct and change the phone number if it is inaccessible
  | SuggestedActionViewChecksHint -- ^ Suggests the user to view a hint about the meaning of one and two check marks on sent messages
  | SuggestedActionConvertToBroadcastGroup -- ^ Suggests the user to convert specified supergroup to a broadcast group
    { SuggestedAction -> Maybe Int
supergroup_id :: Maybe Int -- ^ Supergroup identifier
    }
  | SuggestedActionSetPassword -- ^ Suggests the user to set a 2-step verification password to be able to log in again
    { SuggestedAction -> Maybe Int
authorization_delay :: Maybe Int -- ^ The number of days to pass between consecutive authorizations if the user declines to set password; if 0, then the user is advised to set the password for security reasons
    }
  | SuggestedActionUpgradePremium -- ^ Suggests the user to upgrade the Premium subscription from monthly payments to annual payments
  | SuggestedActionRestorePremium -- ^ Suggests the user to restore a recently expired Premium subscription
  | SuggestedActionSubscribeToAnnualPremium -- ^ Suggests the user to subscribe to the Premium subscription with annual payments
  | SuggestedActionGiftPremiumForChristmas -- ^ Suggests the user to gift Telegram Premium to friends for Christmas
  | SuggestedActionSetBirthdate -- ^ Suggests the user to set birthdate
  | SuggestedActionExtendPremium -- ^ Suggests the user to extend their expiring Telegram Premium subscription
    { SuggestedAction -> Maybe Text
manage_premium_subscription_url :: Maybe T.Text -- ^ A URL for managing Telegram Premium subscription
    }
  | SuggestedActionExtendStarSubscriptions -- ^ Suggests the user to extend their expiring Telegram Star subscriptions. Call getStarSubscriptions with only_expiring == true to get the number of expiring subscriptions and the number of required to buy Telegram Stars
  deriving (SuggestedAction -> SuggestedAction -> Bool
(SuggestedAction -> SuggestedAction -> Bool)
-> (SuggestedAction -> SuggestedAction -> Bool)
-> Eq SuggestedAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SuggestedAction -> SuggestedAction -> Bool
== :: SuggestedAction -> SuggestedAction -> Bool
$c/= :: SuggestedAction -> SuggestedAction -> Bool
/= :: SuggestedAction -> SuggestedAction -> Bool
Eq, Int -> SuggestedAction -> ShowS
[SuggestedAction] -> ShowS
SuggestedAction -> String
(Int -> SuggestedAction -> ShowS)
-> (SuggestedAction -> String)
-> ([SuggestedAction] -> ShowS)
-> Show SuggestedAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SuggestedAction -> ShowS
showsPrec :: Int -> SuggestedAction -> ShowS
$cshow :: SuggestedAction -> String
show :: SuggestedAction -> String
$cshowList :: [SuggestedAction] -> ShowS
showList :: [SuggestedAction] -> ShowS
Show)

instance I.ShortShow SuggestedAction where
  shortShow :: SuggestedAction -> String
shortShow SuggestedAction
SuggestedActionEnableArchiveAndMuteNewChats
      = String
"SuggestedActionEnableArchiveAndMuteNewChats"
  shortShow SuggestedAction
SuggestedActionCheckPassword
      = String
"SuggestedActionCheckPassword"
  shortShow SuggestedAction
SuggestedActionCheckPhoneNumber
      = String
"SuggestedActionCheckPhoneNumber"
  shortShow SuggestedAction
SuggestedActionViewChecksHint
      = String
"SuggestedActionViewChecksHint"
  shortShow SuggestedActionConvertToBroadcastGroup
    { supergroup_id :: SuggestedAction -> Maybe Int
supergroup_id = Maybe Int
supergroup_id_
    }
      = String
"SuggestedActionConvertToBroadcastGroup"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"supergroup_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
supergroup_id_
        ]
  shortShow SuggestedActionSetPassword
    { authorization_delay :: SuggestedAction -> Maybe Int
authorization_delay = Maybe Int
authorization_delay_
    }
      = String
"SuggestedActionSetPassword"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"authorization_delay" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
authorization_delay_
        ]
  shortShow SuggestedAction
SuggestedActionUpgradePremium
      = String
"SuggestedActionUpgradePremium"
  shortShow SuggestedAction
SuggestedActionRestorePremium
      = String
"SuggestedActionRestorePremium"
  shortShow SuggestedAction
SuggestedActionSubscribeToAnnualPremium
      = String
"SuggestedActionSubscribeToAnnualPremium"
  shortShow SuggestedAction
SuggestedActionGiftPremiumForChristmas
      = String
"SuggestedActionGiftPremiumForChristmas"
  shortShow SuggestedAction
SuggestedActionSetBirthdate
      = String
"SuggestedActionSetBirthdate"
  shortShow SuggestedActionExtendPremium
    { manage_premium_subscription_url :: SuggestedAction -> Maybe Text
manage_premium_subscription_url = Maybe Text
manage_premium_subscription_url_
    }
      = String
"SuggestedActionExtendPremium"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"manage_premium_subscription_url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
manage_premium_subscription_url_
        ]
  shortShow SuggestedAction
SuggestedActionExtendStarSubscriptions
      = String
"SuggestedActionExtendStarSubscriptions"

instance AT.FromJSON SuggestedAction where
  parseJSON :: Value -> Parser SuggestedAction
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
"suggestedActionEnableArchiveAndMuteNewChats" -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionEnableArchiveAndMuteNewChats
      String
"suggestedActionCheckPassword"                -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionCheckPassword
      String
"suggestedActionCheckPhoneNumber"             -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionCheckPhoneNumber
      String
"suggestedActionViewChecksHint"               -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionViewChecksHint
      String
"suggestedActionConvertToBroadcastGroup"      -> Value -> Parser SuggestedAction
parseSuggestedActionConvertToBroadcastGroup Value
v
      String
"suggestedActionSetPassword"                  -> Value -> Parser SuggestedAction
parseSuggestedActionSetPassword Value
v
      String
"suggestedActionUpgradePremium"               -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionUpgradePremium
      String
"suggestedActionRestorePremium"               -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionRestorePremium
      String
"suggestedActionSubscribeToAnnualPremium"     -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionSubscribeToAnnualPremium
      String
"suggestedActionGiftPremiumForChristmas"      -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionGiftPremiumForChristmas
      String
"suggestedActionSetBirthdate"                 -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionSetBirthdate
      String
"suggestedActionExtendPremium"                -> Value -> Parser SuggestedAction
parseSuggestedActionExtendPremium Value
v
      String
"suggestedActionExtendStarSubscriptions"      -> SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SuggestedAction
SuggestedActionExtendStarSubscriptions
      String
_                                             -> Parser SuggestedAction
forall a. Monoid a => a
mempty
    
    where
      parseSuggestedActionConvertToBroadcastGroup :: A.Value -> AT.Parser SuggestedAction
      parseSuggestedActionConvertToBroadcastGroup :: Value -> Parser SuggestedAction
parseSuggestedActionConvertToBroadcastGroup = String
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SuggestedActionConvertToBroadcastGroup" ((Object -> Parser SuggestedAction)
 -> Value -> Parser SuggestedAction)
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
supergroup_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"supergroup_id"
        SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SuggestedAction -> Parser SuggestedAction)
-> SuggestedAction -> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ SuggestedActionConvertToBroadcastGroup
          { supergroup_id :: Maybe Int
supergroup_id = Maybe Int
supergroup_id_
          }
      parseSuggestedActionSetPassword :: A.Value -> AT.Parser SuggestedAction
      parseSuggestedActionSetPassword :: Value -> Parser SuggestedAction
parseSuggestedActionSetPassword = String
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SuggestedActionSetPassword" ((Object -> Parser SuggestedAction)
 -> Value -> Parser SuggestedAction)
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
authorization_delay_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"authorization_delay"
        SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SuggestedAction -> Parser SuggestedAction)
-> SuggestedAction -> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ SuggestedActionSetPassword
          { authorization_delay :: Maybe Int
authorization_delay = Maybe Int
authorization_delay_
          }
      parseSuggestedActionExtendPremium :: A.Value -> AT.Parser SuggestedAction
      parseSuggestedActionExtendPremium :: Value -> Parser SuggestedAction
parseSuggestedActionExtendPremium = String
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SuggestedActionExtendPremium" ((Object -> Parser SuggestedAction)
 -> Value -> Parser SuggestedAction)
-> (Object -> Parser SuggestedAction)
-> Value
-> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
manage_premium_subscription_url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"manage_premium_subscription_url"
        SuggestedAction -> Parser SuggestedAction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SuggestedAction -> Parser SuggestedAction)
-> SuggestedAction -> Parser SuggestedAction
forall a b. (a -> b) -> a -> b
$ SuggestedActionExtendPremium
          { manage_premium_subscription_url :: Maybe Text
manage_premium_subscription_url = Maybe Text
manage_premium_subscription_url_
          }
  parseJSON Value
_ = Parser SuggestedAction
forall a. Monoid a => a
mempty

instance AT.ToJSON SuggestedAction where
  toJSON :: SuggestedAction -> Value
toJSON SuggestedAction
SuggestedActionEnableArchiveAndMuteNewChats
      = [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
"suggestedActionEnableArchiveAndMuteNewChats"
        ]
  toJSON SuggestedAction
SuggestedActionCheckPassword
      = [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
"suggestedActionCheckPassword"
        ]
  toJSON SuggestedAction
SuggestedActionCheckPhoneNumber
      = [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
"suggestedActionCheckPhoneNumber"
        ]
  toJSON SuggestedAction
SuggestedActionViewChecksHint
      = [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
"suggestedActionViewChecksHint"
        ]
  toJSON SuggestedActionConvertToBroadcastGroup
    { supergroup_id :: SuggestedAction -> Maybe Int
supergroup_id = Maybe Int
supergroup_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
"suggestedActionConvertToBroadcastGroup"
        , Key
"supergroup_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
supergroup_id_
        ]
  toJSON SuggestedActionSetPassword
    { authorization_delay :: SuggestedAction -> Maybe Int
authorization_delay = Maybe Int
authorization_delay_
    }
      = [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
"suggestedActionSetPassword"
        , Key
"authorization_delay" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
authorization_delay_
        ]
  toJSON SuggestedAction
SuggestedActionUpgradePremium
      = [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
"suggestedActionUpgradePremium"
        ]
  toJSON SuggestedAction
SuggestedActionRestorePremium
      = [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
"suggestedActionRestorePremium"
        ]
  toJSON SuggestedAction
SuggestedActionSubscribeToAnnualPremium
      = [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
"suggestedActionSubscribeToAnnualPremium"
        ]
  toJSON SuggestedAction
SuggestedActionGiftPremiumForChristmas
      = [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
"suggestedActionGiftPremiumForChristmas"
        ]
  toJSON SuggestedAction
SuggestedActionSetBirthdate
      = [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
"suggestedActionSetBirthdate"
        ]
  toJSON SuggestedActionExtendPremium
    { manage_premium_subscription_url :: SuggestedAction -> Maybe Text
manage_premium_subscription_url = Maybe Text
manage_premium_subscription_url_
    }
      = [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
"suggestedActionExtendPremium"
        , Key
"manage_premium_subscription_url" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
manage_premium_subscription_url_
        ]
  toJSON SuggestedAction
SuggestedActionExtendStarSubscriptions
      = [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
"suggestedActionExtendStarSubscriptions"
        ]