{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
module StripeAPI.Types.Rule where
import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.ByteString.Char8
import qualified Data.ByteString.Char8 as Data.ByteString.Internal
import qualified Data.Functor
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified StripeAPI.Common
import StripeAPI.TypeAlias
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe
data Rule = Rule
{
Rule -> Text
ruleAction :: Data.Text.Internal.Text,
Rule -> Text
ruleId :: Data.Text.Internal.Text,
Rule -> Text
rulePredicate :: Data.Text.Internal.Text
}
deriving
( Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
GHC.Show.Show,
Rule -> Rule -> Bool
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
GHC.Classes.Eq
)
instance Data.Aeson.Types.ToJSON.ToJSON Rule where
toJSON :: Rule -> Value
toJSON Rule
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"action" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
ruleAction Rule
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
ruleId Rule
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"predicate" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
rulePredicate Rule
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
toEncoding :: Rule -> Encoding
toEncoding Rule
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"action" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
ruleAction Rule
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"id" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
ruleId Rule
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"predicate" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Rule -> Text
rulePredicate Rule
obj)))
instance Data.Aeson.Types.FromJSON.FromJSON Rule where
parseJSON :: Value -> Parser Rule
parseJSON = String -> (Object -> Parser Rule) -> Value -> Parser Rule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Rule" (\Object
obj -> (((Text -> Text -> Text -> Rule)
-> Parser (Text -> Text -> Text -> Rule)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Text -> Text -> Text -> Rule
Rule Parser (Text -> Text -> Text -> Rule)
-> Parser Text -> Parser (Text -> Text -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"action")) Parser (Text -> Text -> Rule)
-> Parser Text -> Parser (Text -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"id")) Parser (Text -> Rule) -> Parser Text -> Parser Rule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"predicate"))
mkRule ::
Data.Text.Internal.Text ->
Data.Text.Internal.Text ->
Data.Text.Internal.Text ->
Rule
mkRule :: Text -> Text -> Text -> Rule
mkRule Text
ruleAction Text
ruleId Text
rulePredicate =
Rule :: Text -> Text -> Text -> Rule
Rule
{ ruleAction :: Text
ruleAction = Text
ruleAction,
ruleId :: Text
ruleId = Text
ruleId,
rulePredicate :: Text
rulePredicate = Text
rulePredicate
}