module TD.Data.StarSubscriptionPricing
  ( StarSubscriptionPricing(..)    
  , defaultStarSubscriptionPricing 
  ) where

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

data StarSubscriptionPricing
  = StarSubscriptionPricing -- ^ Describes subscription plan paid in Telegram Stars
    { StarSubscriptionPricing -> Maybe Int
period     :: Maybe Int -- ^ The number of seconds between consecutive Telegram Star debiting
    , StarSubscriptionPricing -> Maybe Int
star_count :: Maybe Int -- ^ The amount of Telegram Stars that must be paid for each period
    }
  deriving (StarSubscriptionPricing -> StarSubscriptionPricing -> Bool
(StarSubscriptionPricing -> StarSubscriptionPricing -> Bool)
-> (StarSubscriptionPricing -> StarSubscriptionPricing -> Bool)
-> Eq StarSubscriptionPricing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StarSubscriptionPricing -> StarSubscriptionPricing -> Bool
== :: StarSubscriptionPricing -> StarSubscriptionPricing -> Bool
$c/= :: StarSubscriptionPricing -> StarSubscriptionPricing -> Bool
/= :: StarSubscriptionPricing -> StarSubscriptionPricing -> Bool
Eq, Int -> StarSubscriptionPricing -> ShowS
[StarSubscriptionPricing] -> ShowS
StarSubscriptionPricing -> String
(Int -> StarSubscriptionPricing -> ShowS)
-> (StarSubscriptionPricing -> String)
-> ([StarSubscriptionPricing] -> ShowS)
-> Show StarSubscriptionPricing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StarSubscriptionPricing -> ShowS
showsPrec :: Int -> StarSubscriptionPricing -> ShowS
$cshow :: StarSubscriptionPricing -> String
show :: StarSubscriptionPricing -> String
$cshowList :: [StarSubscriptionPricing] -> ShowS
showList :: [StarSubscriptionPricing] -> ShowS
Show)

instance I.ShortShow StarSubscriptionPricing where
  shortShow :: StarSubscriptionPricing -> String
shortShow StarSubscriptionPricing
    { period :: StarSubscriptionPricing -> Maybe Int
period     = Maybe Int
period_
    , star_count :: StarSubscriptionPricing -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = String
"StarSubscriptionPricing"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"period"     String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
period_
        , String
"star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
        ]

instance AT.FromJSON StarSubscriptionPricing where
  parseJSON :: Value -> Parser StarSubscriptionPricing
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
"starSubscriptionPricing" -> Value -> Parser StarSubscriptionPricing
parseStarSubscriptionPricing Value
v
      String
_                         -> Parser StarSubscriptionPricing
forall a. Monoid a => a
mempty
    
    where
      parseStarSubscriptionPricing :: A.Value -> AT.Parser StarSubscriptionPricing
      parseStarSubscriptionPricing :: Value -> Parser StarSubscriptionPricing
parseStarSubscriptionPricing = String
-> (Object -> Parser StarSubscriptionPricing)
-> Value
-> Parser StarSubscriptionPricing
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"StarSubscriptionPricing" ((Object -> Parser StarSubscriptionPricing)
 -> Value -> Parser StarSubscriptionPricing)
-> (Object -> Parser StarSubscriptionPricing)
-> Value
-> Parser StarSubscriptionPricing
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Int
period_     <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"period"
        Maybe Int
star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"star_count"
        StarSubscriptionPricing -> Parser StarSubscriptionPricing
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (StarSubscriptionPricing -> Parser StarSubscriptionPricing)
-> StarSubscriptionPricing -> Parser StarSubscriptionPricing
forall a b. (a -> b) -> a -> b
$ StarSubscriptionPricing
          { period :: Maybe Int
period     = Maybe Int
period_
          , star_count :: Maybe Int
star_count = Maybe Int
star_count_
          }
  parseJSON Value
_ = Parser StarSubscriptionPricing
forall a. Monoid a => a
mempty

instance AT.ToJSON StarSubscriptionPricing where
  toJSON :: StarSubscriptionPricing -> Value
toJSON StarSubscriptionPricing
    { period :: StarSubscriptionPricing -> Maybe Int
period     = Maybe Int
period_
    , star_count :: StarSubscriptionPricing -> Maybe Int
star_count = Maybe Int
star_count_
    }
      = [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
"starSubscriptionPricing"
        , Key
"period"     Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
period_
        , Key
"star_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
star_count_
        ]

defaultStarSubscriptionPricing :: StarSubscriptionPricing
defaultStarSubscriptionPricing :: StarSubscriptionPricing
defaultStarSubscriptionPricing =
  StarSubscriptionPricing
    { period :: Maybe Int
period     = Maybe Int
forall a. Maybe a
Nothing
    , star_count :: Maybe Int
star_count = Maybe Int
forall a. Maybe a
Nothing
    }