module TD.Query.CanPurchaseFromStore
  (CanPurchaseFromStore(..)
  ) 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.StorePaymentPurpose as StorePaymentPurpose

-- | Checks whether an in-store purchase is possible. Must be called before any in-store purchase. Returns 'TD.Data.Ok.Ok'
data CanPurchaseFromStore
  = CanPurchaseFromStore
    { CanPurchaseFromStore -> Maybe StorePaymentPurpose
purpose :: Maybe StorePaymentPurpose.StorePaymentPurpose -- ^ Transaction purpose
    }
  deriving (CanPurchaseFromStore -> CanPurchaseFromStore -> Bool
(CanPurchaseFromStore -> CanPurchaseFromStore -> Bool)
-> (CanPurchaseFromStore -> CanPurchaseFromStore -> Bool)
-> Eq CanPurchaseFromStore
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CanPurchaseFromStore -> CanPurchaseFromStore -> Bool
== :: CanPurchaseFromStore -> CanPurchaseFromStore -> Bool
$c/= :: CanPurchaseFromStore -> CanPurchaseFromStore -> Bool
/= :: CanPurchaseFromStore -> CanPurchaseFromStore -> Bool
Eq, Int -> CanPurchaseFromStore -> ShowS
[CanPurchaseFromStore] -> ShowS
CanPurchaseFromStore -> String
(Int -> CanPurchaseFromStore -> ShowS)
-> (CanPurchaseFromStore -> String)
-> ([CanPurchaseFromStore] -> ShowS)
-> Show CanPurchaseFromStore
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CanPurchaseFromStore -> ShowS
showsPrec :: Int -> CanPurchaseFromStore -> ShowS
$cshow :: CanPurchaseFromStore -> String
show :: CanPurchaseFromStore -> String
$cshowList :: [CanPurchaseFromStore] -> ShowS
showList :: [CanPurchaseFromStore] -> ShowS
Show)

instance I.ShortShow CanPurchaseFromStore where
  shortShow :: CanPurchaseFromStore -> String
shortShow
    CanPurchaseFromStore
      { purpose :: CanPurchaseFromStore -> Maybe StorePaymentPurpose
purpose = Maybe StorePaymentPurpose
purpose_
      }
        = String
"CanPurchaseFromStore"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"purpose" String -> Maybe StorePaymentPurpose -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StorePaymentPurpose
purpose_
          ]

instance AT.ToJSON CanPurchaseFromStore where
  toJSON :: CanPurchaseFromStore -> Value
toJSON
    CanPurchaseFromStore
      { purpose :: CanPurchaseFromStore -> Maybe StorePaymentPurpose
purpose = Maybe StorePaymentPurpose
purpose_
      }
        = [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
"canPurchaseFromStore"
          , Key
"purpose" Key -> Maybe StorePaymentPurpose -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe StorePaymentPurpose
purpose_
          ]