module TD.Data.PremiumGiftCodePaymentOptions
  (PremiumGiftCodePaymentOptions(..)) 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.PremiumGiftCodePaymentOption as PremiumGiftCodePaymentOption

data PremiumGiftCodePaymentOptions
  = PremiumGiftCodePaymentOptions -- ^ Contains a list of options for creating Telegram Premium gift codes or Telegram Premium giveaway
    { PremiumGiftCodePaymentOptions
-> Maybe [PremiumGiftCodePaymentOption]
options :: Maybe [PremiumGiftCodePaymentOption.PremiumGiftCodePaymentOption] -- ^ The list of options
    }
  deriving (PremiumGiftCodePaymentOptions
-> PremiumGiftCodePaymentOptions -> Bool
(PremiumGiftCodePaymentOptions
 -> PremiumGiftCodePaymentOptions -> Bool)
-> (PremiumGiftCodePaymentOptions
    -> PremiumGiftCodePaymentOptions -> Bool)
-> Eq PremiumGiftCodePaymentOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PremiumGiftCodePaymentOptions
-> PremiumGiftCodePaymentOptions -> Bool
== :: PremiumGiftCodePaymentOptions
-> PremiumGiftCodePaymentOptions -> Bool
$c/= :: PremiumGiftCodePaymentOptions
-> PremiumGiftCodePaymentOptions -> Bool
/= :: PremiumGiftCodePaymentOptions
-> PremiumGiftCodePaymentOptions -> Bool
Eq, Int -> PremiumGiftCodePaymentOptions -> ShowS
[PremiumGiftCodePaymentOptions] -> ShowS
PremiumGiftCodePaymentOptions -> String
(Int -> PremiumGiftCodePaymentOptions -> ShowS)
-> (PremiumGiftCodePaymentOptions -> String)
-> ([PremiumGiftCodePaymentOptions] -> ShowS)
-> Show PremiumGiftCodePaymentOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PremiumGiftCodePaymentOptions -> ShowS
showsPrec :: Int -> PremiumGiftCodePaymentOptions -> ShowS
$cshow :: PremiumGiftCodePaymentOptions -> String
show :: PremiumGiftCodePaymentOptions -> String
$cshowList :: [PremiumGiftCodePaymentOptions] -> ShowS
showList :: [PremiumGiftCodePaymentOptions] -> ShowS
Show)

instance I.ShortShow PremiumGiftCodePaymentOptions where
  shortShow :: PremiumGiftCodePaymentOptions -> String
shortShow PremiumGiftCodePaymentOptions
    { options :: PremiumGiftCodePaymentOptions
-> Maybe [PremiumGiftCodePaymentOption]
options = Maybe [PremiumGiftCodePaymentOption]
options_
    }
      = String
"PremiumGiftCodePaymentOptions"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"options" String -> Maybe [PremiumGiftCodePaymentOption] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [PremiumGiftCodePaymentOption]
options_
        ]

instance AT.FromJSON PremiumGiftCodePaymentOptions where
  parseJSON :: Value -> Parser PremiumGiftCodePaymentOptions
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
"premiumGiftCodePaymentOptions" -> Value -> Parser PremiumGiftCodePaymentOptions
parsePremiumGiftCodePaymentOptions Value
v
      String
_                               -> Parser PremiumGiftCodePaymentOptions
forall a. Monoid a => a
mempty
    
    where
      parsePremiumGiftCodePaymentOptions :: A.Value -> AT.Parser PremiumGiftCodePaymentOptions
      parsePremiumGiftCodePaymentOptions :: Value -> Parser PremiumGiftCodePaymentOptions
parsePremiumGiftCodePaymentOptions = String
-> (Object -> Parser PremiumGiftCodePaymentOptions)
-> Value
-> Parser PremiumGiftCodePaymentOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PremiumGiftCodePaymentOptions" ((Object -> Parser PremiumGiftCodePaymentOptions)
 -> Value -> Parser PremiumGiftCodePaymentOptions)
-> (Object -> Parser PremiumGiftCodePaymentOptions)
-> Value
-> Parser PremiumGiftCodePaymentOptions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe [PremiumGiftCodePaymentOption]
options_ <- Object
o Object -> Key -> Parser (Maybe [PremiumGiftCodePaymentOption])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"options"
        PremiumGiftCodePaymentOptions
-> Parser PremiumGiftCodePaymentOptions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PremiumGiftCodePaymentOptions
 -> Parser PremiumGiftCodePaymentOptions)
-> PremiumGiftCodePaymentOptions
-> Parser PremiumGiftCodePaymentOptions
forall a b. (a -> b) -> a -> b
$ PremiumGiftCodePaymentOptions
          { options :: Maybe [PremiumGiftCodePaymentOption]
options = Maybe [PremiumGiftCodePaymentOption]
options_
          }
  parseJSON Value
_ = Parser PremiumGiftCodePaymentOptions
forall a. Monoid a => a
mempty