module TD.Data.AcceptedGiftTypes
  ( AcceptedGiftTypes(..)    
  , defaultAcceptedGiftTypes 
  ) where

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

data AcceptedGiftTypes
  = AcceptedGiftTypes -- ^ Describes gift types that are accepted by a user
    { AcceptedGiftTypes -> Maybe Bool
unlimited_gifts      :: Maybe Bool -- ^ True, if unlimited regular gifts are accepted
    , AcceptedGiftTypes -> Maybe Bool
limited_gifts        :: Maybe Bool -- ^ True, if limited regular gifts are accepted
    , AcceptedGiftTypes -> Maybe Bool
upgraded_gifts       :: Maybe Bool -- ^ True, if upgraded gifts and regular gifts that can be upgraded for free are accepted
    , AcceptedGiftTypes -> Maybe Bool
premium_subscription :: Maybe Bool -- ^ True, if Telegram Premium subscription is accepted
    }
  deriving (AcceptedGiftTypes -> AcceptedGiftTypes -> Bool
(AcceptedGiftTypes -> AcceptedGiftTypes -> Bool)
-> (AcceptedGiftTypes -> AcceptedGiftTypes -> Bool)
-> Eq AcceptedGiftTypes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AcceptedGiftTypes -> AcceptedGiftTypes -> Bool
== :: AcceptedGiftTypes -> AcceptedGiftTypes -> Bool
$c/= :: AcceptedGiftTypes -> AcceptedGiftTypes -> Bool
/= :: AcceptedGiftTypes -> AcceptedGiftTypes -> Bool
Eq, Int -> AcceptedGiftTypes -> ShowS
[AcceptedGiftTypes] -> ShowS
AcceptedGiftTypes -> String
(Int -> AcceptedGiftTypes -> ShowS)
-> (AcceptedGiftTypes -> String)
-> ([AcceptedGiftTypes] -> ShowS)
-> Show AcceptedGiftTypes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AcceptedGiftTypes -> ShowS
showsPrec :: Int -> AcceptedGiftTypes -> ShowS
$cshow :: AcceptedGiftTypes -> String
show :: AcceptedGiftTypes -> String
$cshowList :: [AcceptedGiftTypes] -> ShowS
showList :: [AcceptedGiftTypes] -> ShowS
Show)

instance I.ShortShow AcceptedGiftTypes where
  shortShow :: AcceptedGiftTypes -> String
shortShow AcceptedGiftTypes
    { unlimited_gifts :: AcceptedGiftTypes -> Maybe Bool
unlimited_gifts      = Maybe Bool
unlimited_gifts_
    , limited_gifts :: AcceptedGiftTypes -> Maybe Bool
limited_gifts        = Maybe Bool
limited_gifts_
    , upgraded_gifts :: AcceptedGiftTypes -> Maybe Bool
upgraded_gifts       = Maybe Bool
upgraded_gifts_
    , premium_subscription :: AcceptedGiftTypes -> Maybe Bool
premium_subscription = Maybe Bool
premium_subscription_
    }
      = String
"AcceptedGiftTypes"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"unlimited_gifts"      String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
unlimited_gifts_
        , String
"limited_gifts"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
limited_gifts_
        , String
"upgraded_gifts"       String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
upgraded_gifts_
        , String
"premium_subscription" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
premium_subscription_
        ]

instance AT.FromJSON AcceptedGiftTypes where
  parseJSON :: Value -> Parser AcceptedGiftTypes
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
"acceptedGiftTypes" -> Value -> Parser AcceptedGiftTypes
parseAcceptedGiftTypes Value
v
      String
_                   -> Parser AcceptedGiftTypes
forall a. Monoid a => a
mempty
    
    where
      parseAcceptedGiftTypes :: A.Value -> AT.Parser AcceptedGiftTypes
      parseAcceptedGiftTypes :: Value -> Parser AcceptedGiftTypes
parseAcceptedGiftTypes = String
-> (Object -> Parser AcceptedGiftTypes)
-> Value
-> Parser AcceptedGiftTypes
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"AcceptedGiftTypes" ((Object -> Parser AcceptedGiftTypes)
 -> Value -> Parser AcceptedGiftTypes)
-> (Object -> Parser AcceptedGiftTypes)
-> Value
-> Parser AcceptedGiftTypes
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Bool
unlimited_gifts_      <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"unlimited_gifts"
        Maybe Bool
limited_gifts_        <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"limited_gifts"
        Maybe Bool
upgraded_gifts_       <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"upgraded_gifts"
        Maybe Bool
premium_subscription_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"premium_subscription"
        AcceptedGiftTypes -> Parser AcceptedGiftTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AcceptedGiftTypes -> Parser AcceptedGiftTypes)
-> AcceptedGiftTypes -> Parser AcceptedGiftTypes
forall a b. (a -> b) -> a -> b
$ AcceptedGiftTypes
          { unlimited_gifts :: Maybe Bool
unlimited_gifts      = Maybe Bool
unlimited_gifts_
          , limited_gifts :: Maybe Bool
limited_gifts        = Maybe Bool
limited_gifts_
          , upgraded_gifts :: Maybe Bool
upgraded_gifts       = Maybe Bool
upgraded_gifts_
          , premium_subscription :: Maybe Bool
premium_subscription = Maybe Bool
premium_subscription_
          }
  parseJSON Value
_ = Parser AcceptedGiftTypes
forall a. Monoid a => a
mempty

instance AT.ToJSON AcceptedGiftTypes where
  toJSON :: AcceptedGiftTypes -> Value
toJSON AcceptedGiftTypes
    { unlimited_gifts :: AcceptedGiftTypes -> Maybe Bool
unlimited_gifts      = Maybe Bool
unlimited_gifts_
    , limited_gifts :: AcceptedGiftTypes -> Maybe Bool
limited_gifts        = Maybe Bool
limited_gifts_
    , upgraded_gifts :: AcceptedGiftTypes -> Maybe Bool
upgraded_gifts       = Maybe Bool
upgraded_gifts_
    , premium_subscription :: AcceptedGiftTypes -> Maybe Bool
premium_subscription = Maybe Bool
premium_subscription_
    }
      = [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
"acceptedGiftTypes"
        , Key
"unlimited_gifts"      Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
unlimited_gifts_
        , Key
"limited_gifts"        Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
limited_gifts_
        , Key
"upgraded_gifts"       Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
upgraded_gifts_
        , Key
"premium_subscription" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
premium_subscription_
        ]

defaultAcceptedGiftTypes :: AcceptedGiftTypes
defaultAcceptedGiftTypes :: AcceptedGiftTypes
defaultAcceptedGiftTypes =
  AcceptedGiftTypes
    { unlimited_gifts :: Maybe Bool
unlimited_gifts      = Maybe Bool
forall a. Maybe a
Nothing
    , limited_gifts :: Maybe Bool
limited_gifts        = Maybe Bool
forall a. Maybe a
Nothing
    , upgraded_gifts :: Maybe Bool
upgraded_gifts       = Maybe Bool
forall a. Maybe a
Nothing
    , premium_subscription :: Maybe Bool
premium_subscription = Maybe Bool
forall a. Maybe a
Nothing
    }