module TD.Data.StarPaymentOptions
  (StarPaymentOptions(..)) 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.StarPaymentOption as StarPaymentOption

data StarPaymentOptions
  = StarPaymentOptions -- ^ Contains a list of options for buying Telegram Stars
    { StarPaymentOptions -> Maybe [StarPaymentOption]
options :: Maybe [StarPaymentOption.StarPaymentOption] -- ^ The list of options
    }
  deriving (StarPaymentOptions -> StarPaymentOptions -> Bool
(StarPaymentOptions -> StarPaymentOptions -> Bool)
-> (StarPaymentOptions -> StarPaymentOptions -> Bool)
-> Eq StarPaymentOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarPaymentOptions -> StarPaymentOptions -> Bool
== :: StarPaymentOptions -> StarPaymentOptions -> Bool
$c/= :: StarPaymentOptions -> StarPaymentOptions -> Bool
/= :: StarPaymentOptions -> StarPaymentOptions -> Bool
Eq, Int -> StarPaymentOptions -> ShowS
[StarPaymentOptions] -> ShowS
StarPaymentOptions -> String
(Int -> StarPaymentOptions -> ShowS)
-> (StarPaymentOptions -> String)
-> ([StarPaymentOptions] -> ShowS)
-> Show StarPaymentOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarPaymentOptions -> ShowS
showsPrec :: Int -> StarPaymentOptions -> ShowS
$cshow :: StarPaymentOptions -> String
show :: StarPaymentOptions -> String
$cshowList :: [StarPaymentOptions] -> ShowS
showList :: [StarPaymentOptions] -> ShowS
Show)

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

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