{-# LANGUAGE TemplateHaskell #-}

-- | These are types for Scheduled Trigger definition; see "Hasura.Eventing.ScheduledTrigger"
module Hasura.RQL.Types.ScheduledTrigger
  ( ScheduledTriggerName (..),
    CronTriggerMetadata (..),
    CreateCronTrigger (..),
    STRetryConf (..),
    CreateScheduledEvent (..),
    CronEventId,
    OneOffScheduledEventId,
    formatTime',
    defaultSTRetryConf,
    ScheduledEventId,
    InvocationId,
    CronEventSeed (..),
    OneOffEvent,
    ScheduledEventStatus (..),
    scheduledEventStatusToText,
    ScheduledEventType (..),
    ScheduledEvent (..),
    ScheduledEventInvocation (..),
    OneOffScheduledEvent (..),
    CronEvent (..),
    ScheduledEventPagination (..),
    GetScheduledEvents (..),
    WithTotalCount (..),
    DeleteScheduledEvent (..),
    GetInvocationsBy (..),
    GetEventInvocations (..),
    ClearCronEvents (..),
    cctName,
    cctWebhook,
    cctCronSchedule,
    cctPayload,
    cctRetryConf,
    cctHeaders,
    cctIncludeInMetadata,
    cctComment,
    cctReplace,
    cctRequestTransform,
    cctResponseTransform,
  )
where

import Control.Lens (makeLenses)
import Data.Aeson
import Data.Aeson qualified as J
import Data.Aeson.Casing
import Data.Aeson.TH
import Data.Aeson.Types
import Data.Text qualified as T
import Data.Time.Clock
import Data.Time.Clock.Units
import Data.Time.Format.ISO8601
import Database.PG.Query qualified as Q
import Hasura.Incremental
import Hasura.Prelude
import Hasura.RQL.DDL.Webhook.Transform (MetadataResponseTransform, RequestTransform)
import Hasura.RQL.Types.Common (InputWebhook (..))
import Hasura.RQL.Types.EventTrigger
import Hasura.RQL.Types.Eventing
import Hasura.RQL.Types.Numeric (NonNegativeDiffTime, unsafeNonNegativeDiffTime)
import PostgreSQL.Binary.Decoding qualified as PD
import System.Cron.Types

type CronEventId = EventId

type OneOffScheduledEventId = EventId

type ScheduledEventId = EventId

type InvocationId = Text

data STRetryConf = STRetryConf
  { STRetryConf -> Int
strcNumRetries :: Int,
    STRetryConf -> NonNegativeDiffTime
strcRetryIntervalSeconds :: NonNegativeDiffTime,
    STRetryConf -> NonNegativeDiffTime
strcTimeoutSeconds :: NonNegativeDiffTime,
    -- | The tolerance configuration is used to determine whether a scheduled
    --   event is not too old to process. The age of the scheduled event is the
    --   difference between the current timestamp and the scheduled event's
    --   timestamp, if the age is than the tolerance then the scheduled event
    --   is marked as dead.
    STRetryConf -> NonNegativeDiffTime
strcToleranceSeconds :: NonNegativeDiffTime
  }
  deriving (Int -> STRetryConf -> ShowS
[STRetryConf] -> ShowS
STRetryConf -> String
(Int -> STRetryConf -> ShowS)
-> (STRetryConf -> String)
-> ([STRetryConf] -> ShowS)
-> Show STRetryConf
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [STRetryConf] -> ShowS
$cshowList :: [STRetryConf] -> ShowS
show :: STRetryConf -> String
$cshow :: STRetryConf -> String
showsPrec :: Int -> STRetryConf -> ShowS
$cshowsPrec :: Int -> STRetryConf -> ShowS
Show, STRetryConf -> STRetryConf -> Bool
(STRetryConf -> STRetryConf -> Bool)
-> (STRetryConf -> STRetryConf -> Bool) -> Eq STRetryConf
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: STRetryConf -> STRetryConf -> Bool
$c/= :: STRetryConf -> STRetryConf -> Bool
== :: STRetryConf -> STRetryConf -> Bool
$c== :: STRetryConf -> STRetryConf -> Bool
Eq, (forall x. STRetryConf -> Rep STRetryConf x)
-> (forall x. Rep STRetryConf x -> STRetryConf)
-> Generic STRetryConf
forall x. Rep STRetryConf x -> STRetryConf
forall x. STRetryConf -> Rep STRetryConf x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep STRetryConf x -> STRetryConf
$cfrom :: forall x. STRetryConf -> Rep STRetryConf x
Generic)

instance NFData STRetryConf

instance Cacheable STRetryConf

instance FromJSON STRetryConf where
  parseJSON :: Value -> Parser STRetryConf
parseJSON = String
-> (Object -> Parser STRetryConf) -> Value -> Parser STRetryConf
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"STRetryConf" \Object
o -> do
    Int
numRetries' <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"num_retries" Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
0
    NonNegativeDiffTime
retryInterval <-
      Object
o Object -> Key -> Parser (Maybe NonNegativeDiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_interval_seconds" Parser (Maybe NonNegativeDiffTime)
-> NonNegativeDiffTime -> Parser NonNegativeDiffTime
forall a. Parser (Maybe a) -> a -> Parser a
.!= DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (Seconds -> DiffTime
seconds Seconds
10)
    NonNegativeDiffTime
timeout <-
      Object
o Object -> Key -> Parser (Maybe NonNegativeDiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"timeout_seconds" Parser (Maybe NonNegativeDiffTime)
-> NonNegativeDiffTime -> Parser NonNegativeDiffTime
forall a. Parser (Maybe a) -> a -> Parser a
.!= DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (Seconds -> DiffTime
seconds Seconds
60)
    NonNegativeDiffTime
tolerance <-
      Object
o Object -> Key -> Parser (Maybe NonNegativeDiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"tolerance_seconds" Parser (Maybe NonNegativeDiffTime)
-> NonNegativeDiffTime -> Parser NonNegativeDiffTime
forall a. Parser (Maybe a) -> a -> Parser a
.!= DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (Hours -> DiffTime
hours Hours
6)
    if Int
numRetries' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
      then String -> Parser STRetryConf
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"num_retries cannot be a negative value"
      else STRetryConf -> Parser STRetryConf
forall (f :: * -> *) a. Applicative f => a -> f a
pure (STRetryConf -> Parser STRetryConf)
-> STRetryConf -> Parser STRetryConf
forall a b. (a -> b) -> a -> b
$ Int
-> NonNegativeDiffTime
-> NonNegativeDiffTime
-> NonNegativeDiffTime
-> STRetryConf
STRetryConf Int
numRetries' NonNegativeDiffTime
retryInterval NonNegativeDiffTime
timeout NonNegativeDiffTime
tolerance

$(deriveToJSON hasuraJSON {omitNothingFields = True} ''STRetryConf)

defaultSTRetryConf :: STRetryConf
defaultSTRetryConf :: STRetryConf
defaultSTRetryConf =
  STRetryConf :: Int
-> NonNegativeDiffTime
-> NonNegativeDiffTime
-> NonNegativeDiffTime
-> STRetryConf
STRetryConf
    { strcNumRetries :: Int
strcNumRetries = Int
0,
      strcRetryIntervalSeconds :: NonNegativeDiffTime
strcRetryIntervalSeconds = DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (DiffTime -> NonNegativeDiffTime)
-> DiffTime -> NonNegativeDiffTime
forall a b. (a -> b) -> a -> b
$ Seconds -> DiffTime
seconds Seconds
10,
      strcTimeoutSeconds :: NonNegativeDiffTime
strcTimeoutSeconds = DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (DiffTime -> NonNegativeDiffTime)
-> DiffTime -> NonNegativeDiffTime
forall a b. (a -> b) -> a -> b
$ Seconds -> DiffTime
seconds Seconds
60,
      strcToleranceSeconds :: NonNegativeDiffTime
strcToleranceSeconds = DiffTime -> NonNegativeDiffTime
unsafeNonNegativeDiffTime (DiffTime -> NonNegativeDiffTime)
-> DiffTime -> NonNegativeDiffTime
forall a b. (a -> b) -> a -> b
$ Hours -> DiffTime
hours Hours
6
    }

data CronTriggerMetadata = CronTriggerMetadata
  { CronTriggerMetadata -> TriggerName
ctName :: TriggerName,
    CronTriggerMetadata -> InputWebhook
ctWebhook :: InputWebhook,
    CronTriggerMetadata -> CronSchedule
ctSchedule :: CronSchedule,
    CronTriggerMetadata -> Maybe Value
ctPayload :: Maybe J.Value,
    CronTriggerMetadata -> STRetryConf
ctRetryConf :: STRetryConf,
    CronTriggerMetadata -> [HeaderConf]
ctHeaders :: [HeaderConf],
    CronTriggerMetadata -> Bool
ctIncludeInMetadata :: Bool,
    CronTriggerMetadata -> Maybe Text
ctComment :: Maybe Text,
    CronTriggerMetadata -> Maybe RequestTransform
ctRequestTransform :: Maybe RequestTransform,
    CronTriggerMetadata -> Maybe MetadataResponseTransform
ctResponseTransform :: Maybe MetadataResponseTransform
  }
  deriving (Int -> CronTriggerMetadata -> ShowS
[CronTriggerMetadata] -> ShowS
CronTriggerMetadata -> String
(Int -> CronTriggerMetadata -> ShowS)
-> (CronTriggerMetadata -> String)
-> ([CronTriggerMetadata] -> ShowS)
-> Show CronTriggerMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CronTriggerMetadata] -> ShowS
$cshowList :: [CronTriggerMetadata] -> ShowS
show :: CronTriggerMetadata -> String
$cshow :: CronTriggerMetadata -> String
showsPrec :: Int -> CronTriggerMetadata -> ShowS
$cshowsPrec :: Int -> CronTriggerMetadata -> ShowS
Show, CronTriggerMetadata -> CronTriggerMetadata -> Bool
(CronTriggerMetadata -> CronTriggerMetadata -> Bool)
-> (CronTriggerMetadata -> CronTriggerMetadata -> Bool)
-> Eq CronTriggerMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CronTriggerMetadata -> CronTriggerMetadata -> Bool
$c/= :: CronTriggerMetadata -> CronTriggerMetadata -> Bool
== :: CronTriggerMetadata -> CronTriggerMetadata -> Bool
$c== :: CronTriggerMetadata -> CronTriggerMetadata -> Bool
Eq, (forall x. CronTriggerMetadata -> Rep CronTriggerMetadata x)
-> (forall x. Rep CronTriggerMetadata x -> CronTriggerMetadata)
-> Generic CronTriggerMetadata
forall x. Rep CronTriggerMetadata x -> CronTriggerMetadata
forall x. CronTriggerMetadata -> Rep CronTriggerMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CronTriggerMetadata x -> CronTriggerMetadata
$cfrom :: forall x. CronTriggerMetadata -> Rep CronTriggerMetadata x
Generic)

instance NFData CronTriggerMetadata

instance Cacheable CronTriggerMetadata

instance FromJSON CronTriggerMetadata where
  parseJSON :: Value -> Parser CronTriggerMetadata
parseJSON =
    String
-> (Object -> Parser CronTriggerMetadata)
-> Value
-> Parser CronTriggerMetadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CronTriggerMetadata" ((Object -> Parser CronTriggerMetadata)
 -> Value -> Parser CronTriggerMetadata)
-> (Object -> Parser CronTriggerMetadata)
-> Value
-> Parser CronTriggerMetadata
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
      TriggerName
ctName <- Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
      InputWebhook
ctWebhook <- Object
o Object -> Key -> Parser InputWebhook
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"webhook"
      Maybe Value
ctPayload <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"payload"
      CronSchedule
ctSchedule <- Object
o Object -> Key -> Parser CronSchedule
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"schedule"
      STRetryConf
ctRetryConf <- Object
o Object -> Key -> Parser (Maybe STRetryConf)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_conf" Parser (Maybe STRetryConf) -> STRetryConf -> Parser STRetryConf
forall a. Parser (Maybe a) -> a -> Parser a
.!= STRetryConf
defaultSTRetryConf
      [HeaderConf]
ctHeaders <- Object
o Object -> Key -> Parser (Maybe [HeaderConf])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"headers" Parser (Maybe [HeaderConf]) -> [HeaderConf] -> Parser [HeaderConf]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
      Bool
ctIncludeInMetadata <- Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"include_in_metadata"
      Maybe Text
ctComment <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment"
      Maybe RequestTransform
ctRequestTransform <- Object
o Object -> Key -> Parser (Maybe RequestTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"request_transform"
      Maybe MetadataResponseTransform
ctResponseTransform <- Object
o Object -> Key -> Parser (Maybe MetadataResponseTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"response_transform"
      CronTriggerMetadata -> Parser CronTriggerMetadata
forall (f :: * -> *) a. Applicative f => a -> f a
pure CronTriggerMetadata :: TriggerName
-> InputWebhook
-> CronSchedule
-> Maybe Value
-> STRetryConf
-> [HeaderConf]
-> Bool
-> Maybe Text
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> CronTriggerMetadata
CronTriggerMetadata {Bool
[HeaderConf]
Maybe Value
Maybe Text
Maybe MetadataResponseTransform
Maybe RequestTransform
CronSchedule
InputWebhook
TriggerName
STRetryConf
ctResponseTransform :: Maybe MetadataResponseTransform
ctRequestTransform :: Maybe RequestTransform
ctComment :: Maybe Text
ctIncludeInMetadata :: Bool
ctHeaders :: [HeaderConf]
ctRetryConf :: STRetryConf
ctSchedule :: CronSchedule
ctPayload :: Maybe Value
ctWebhook :: InputWebhook
ctName :: TriggerName
ctResponseTransform :: Maybe MetadataResponseTransform
ctRequestTransform :: Maybe RequestTransform
ctComment :: Maybe Text
ctIncludeInMetadata :: Bool
ctHeaders :: [HeaderConf]
ctRetryConf :: STRetryConf
ctPayload :: Maybe Value
ctSchedule :: CronSchedule
ctWebhook :: InputWebhook
ctName :: TriggerName
..}

$(deriveToJSON hasuraJSON {omitNothingFields = True} ''CronTriggerMetadata)

data CreateCronTrigger = CreateCronTrigger
  { CreateCronTrigger -> TriggerName
_cctName :: TriggerName,
    CreateCronTrigger -> InputWebhook
_cctWebhook :: InputWebhook,
    CreateCronTrigger -> CronSchedule
_cctCronSchedule :: CronSchedule,
    CreateCronTrigger -> Maybe Value
_cctPayload :: Maybe J.Value,
    CreateCronTrigger -> STRetryConf
_cctRetryConf :: STRetryConf,
    CreateCronTrigger -> [HeaderConf]
_cctHeaders :: [HeaderConf],
    CreateCronTrigger -> Bool
_cctIncludeInMetadata :: Bool,
    CreateCronTrigger -> Maybe Text
_cctComment :: Maybe Text,
    CreateCronTrigger -> Bool
_cctReplace :: Bool,
    CreateCronTrigger -> Maybe RequestTransform
_cctRequestTransform :: Maybe RequestTransform,
    CreateCronTrigger -> Maybe MetadataResponseTransform
_cctResponseTransform :: Maybe MetadataResponseTransform
  }
  deriving (Int -> CreateCronTrigger -> ShowS
[CreateCronTrigger] -> ShowS
CreateCronTrigger -> String
(Int -> CreateCronTrigger -> ShowS)
-> (CreateCronTrigger -> String)
-> ([CreateCronTrigger] -> ShowS)
-> Show CreateCronTrigger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCronTrigger] -> ShowS
$cshowList :: [CreateCronTrigger] -> ShowS
show :: CreateCronTrigger -> String
$cshow :: CreateCronTrigger -> String
showsPrec :: Int -> CreateCronTrigger -> ShowS
$cshowsPrec :: Int -> CreateCronTrigger -> ShowS
Show, CreateCronTrigger -> CreateCronTrigger -> Bool
(CreateCronTrigger -> CreateCronTrigger -> Bool)
-> (CreateCronTrigger -> CreateCronTrigger -> Bool)
-> Eq CreateCronTrigger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCronTrigger -> CreateCronTrigger -> Bool
$c/= :: CreateCronTrigger -> CreateCronTrigger -> Bool
== :: CreateCronTrigger -> CreateCronTrigger -> Bool
$c== :: CreateCronTrigger -> CreateCronTrigger -> Bool
Eq, (forall x. CreateCronTrigger -> Rep CreateCronTrigger x)
-> (forall x. Rep CreateCronTrigger x -> CreateCronTrigger)
-> Generic CreateCronTrigger
forall x. Rep CreateCronTrigger x -> CreateCronTrigger
forall x. CreateCronTrigger -> Rep CreateCronTrigger x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCronTrigger x -> CreateCronTrigger
$cfrom :: forall x. CreateCronTrigger -> Rep CreateCronTrigger x
Generic)

$(makeLenses ''CreateCronTrigger)

instance NFData CreateCronTrigger

instance Cacheable CreateCronTrigger

instance FromJSON CreateCronTrigger where
  parseJSON :: Value -> Parser CreateCronTrigger
parseJSON =
    String
-> (Object -> Parser CreateCronTrigger)
-> Value
-> Parser CreateCronTrigger
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CreateCronTrigger" ((Object -> Parser CreateCronTrigger)
 -> Value -> Parser CreateCronTrigger)
-> (Object -> Parser CreateCronTrigger)
-> Value
-> Parser CreateCronTrigger
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
      TriggerName
_cctName <- Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
      InputWebhook
_cctWebhook <- Object
o Object -> Key -> Parser InputWebhook
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"webhook"
      Maybe Value
_cctPayload <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"payload"
      CronSchedule
_cctCronSchedule <- Object
o Object -> Key -> Parser CronSchedule
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"schedule"
      STRetryConf
_cctRetryConf <- Object
o Object -> Key -> Parser (Maybe STRetryConf)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_conf" Parser (Maybe STRetryConf) -> STRetryConf -> Parser STRetryConf
forall a. Parser (Maybe a) -> a -> Parser a
.!= STRetryConf
defaultSTRetryConf
      [HeaderConf]
_cctHeaders <- Object
o Object -> Key -> Parser (Maybe [HeaderConf])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"headers" Parser (Maybe [HeaderConf]) -> [HeaderConf] -> Parser [HeaderConf]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
      Bool
_cctIncludeInMetadata <- Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"include_in_metadata"
      Maybe Text
_cctComment <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment"
      Bool
_cctReplace <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"replace" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
      Maybe RequestTransform
_cctRequestTransform <- Object
o Object -> Key -> Parser (Maybe RequestTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"request_transform"
      Maybe MetadataResponseTransform
_cctResponseTransform <- Object
o Object -> Key -> Parser (Maybe MetadataResponseTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"response_transform"
      CreateCronTrigger -> Parser CreateCronTrigger
forall (f :: * -> *) a. Applicative f => a -> f a
pure CreateCronTrigger :: TriggerName
-> InputWebhook
-> CronSchedule
-> Maybe Value
-> STRetryConf
-> [HeaderConf]
-> Bool
-> Maybe Text
-> Bool
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> CreateCronTrigger
CreateCronTrigger {Bool
[HeaderConf]
Maybe Value
Maybe Text
Maybe MetadataResponseTransform
Maybe RequestTransform
CronSchedule
InputWebhook
TriggerName
STRetryConf
_cctResponseTransform :: Maybe MetadataResponseTransform
_cctRequestTransform :: Maybe RequestTransform
_cctReplace :: Bool
_cctComment :: Maybe Text
_cctIncludeInMetadata :: Bool
_cctHeaders :: [HeaderConf]
_cctRetryConf :: STRetryConf
_cctCronSchedule :: CronSchedule
_cctPayload :: Maybe Value
_cctWebhook :: InputWebhook
_cctName :: TriggerName
_cctResponseTransform :: Maybe MetadataResponseTransform
_cctRequestTransform :: Maybe RequestTransform
_cctReplace :: Bool
_cctComment :: Maybe Text
_cctIncludeInMetadata :: Bool
_cctHeaders :: [HeaderConf]
_cctRetryConf :: STRetryConf
_cctPayload :: Maybe Value
_cctCronSchedule :: CronSchedule
_cctWebhook :: InputWebhook
_cctName :: TriggerName
..}

$(deriveToJSON hasuraJSON {omitNothingFields = True} ''CreateCronTrigger)

newtype ScheduledTriggerName = ScheduledTriggerName {ScheduledTriggerName -> TriggerName
unName :: TriggerName}
  deriving (Int -> ScheduledTriggerName -> ShowS
[ScheduledTriggerName] -> ShowS
ScheduledTriggerName -> String
(Int -> ScheduledTriggerName -> ShowS)
-> (ScheduledTriggerName -> String)
-> ([ScheduledTriggerName] -> ShowS)
-> Show ScheduledTriggerName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledTriggerName] -> ShowS
$cshowList :: [ScheduledTriggerName] -> ShowS
show :: ScheduledTriggerName -> String
$cshow :: ScheduledTriggerName -> String
showsPrec :: Int -> ScheduledTriggerName -> ShowS
$cshowsPrec :: Int -> ScheduledTriggerName -> ShowS
Show, ScheduledTriggerName -> ScheduledTriggerName -> Bool
(ScheduledTriggerName -> ScheduledTriggerName -> Bool)
-> (ScheduledTriggerName -> ScheduledTriggerName -> Bool)
-> Eq ScheduledTriggerName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledTriggerName -> ScheduledTriggerName -> Bool
$c/= :: ScheduledTriggerName -> ScheduledTriggerName -> Bool
== :: ScheduledTriggerName -> ScheduledTriggerName -> Bool
$c== :: ScheduledTriggerName -> ScheduledTriggerName -> Bool
Eq)

$(deriveJSON hasuraJSON ''ScheduledTriggerName)

formatTime' :: UTCTime -> Text
formatTime' :: UTCTime -> Text
formatTime' = String -> Text
T.pack (String -> Text) -> (UTCTime -> String) -> UTCTime -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> String
forall t. ISO8601 t => t -> String
iso8601Show

data CreateScheduledEvent = CreateScheduledEvent
  { CreateScheduledEvent -> InputWebhook
cseWebhook :: InputWebhook,
    -- | The timestamp should be in the
    -- <ISO 8601 https://en.wikipedia.org/wiki/ISO_8601>
    -- format (which is what @aeson@ expects by default for 'UTCTime').
    CreateScheduledEvent -> UTCTime
cseScheduleAt :: UTCTime,
    CreateScheduledEvent -> Maybe Value
csePayload :: Maybe J.Value,
    CreateScheduledEvent -> [HeaderConf]
cseHeaders :: [HeaderConf],
    CreateScheduledEvent -> STRetryConf
cseRetryConf :: STRetryConf,
    CreateScheduledEvent -> Maybe Text
cseComment :: Maybe Text,
    CreateScheduledEvent -> Maybe RequestTransform
cseRequestTransform :: Maybe RequestTransform,
    CreateScheduledEvent -> Maybe MetadataResponseTransform
cseResponseTransform :: Maybe MetadataResponseTransform
  }
  deriving (Int -> CreateScheduledEvent -> ShowS
[CreateScheduledEvent] -> ShowS
CreateScheduledEvent -> String
(Int -> CreateScheduledEvent -> ShowS)
-> (CreateScheduledEvent -> String)
-> ([CreateScheduledEvent] -> ShowS)
-> Show CreateScheduledEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateScheduledEvent] -> ShowS
$cshowList :: [CreateScheduledEvent] -> ShowS
show :: CreateScheduledEvent -> String
$cshow :: CreateScheduledEvent -> String
showsPrec :: Int -> CreateScheduledEvent -> ShowS
$cshowsPrec :: Int -> CreateScheduledEvent -> ShowS
Show, CreateScheduledEvent -> CreateScheduledEvent -> Bool
(CreateScheduledEvent -> CreateScheduledEvent -> Bool)
-> (CreateScheduledEvent -> CreateScheduledEvent -> Bool)
-> Eq CreateScheduledEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateScheduledEvent -> CreateScheduledEvent -> Bool
$c/= :: CreateScheduledEvent -> CreateScheduledEvent -> Bool
== :: CreateScheduledEvent -> CreateScheduledEvent -> Bool
$c== :: CreateScheduledEvent -> CreateScheduledEvent -> Bool
Eq, (forall x. CreateScheduledEvent -> Rep CreateScheduledEvent x)
-> (forall x. Rep CreateScheduledEvent x -> CreateScheduledEvent)
-> Generic CreateScheduledEvent
forall x. Rep CreateScheduledEvent x -> CreateScheduledEvent
forall x. CreateScheduledEvent -> Rep CreateScheduledEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateScheduledEvent x -> CreateScheduledEvent
$cfrom :: forall x. CreateScheduledEvent -> Rep CreateScheduledEvent x
Generic)

instance FromJSON CreateScheduledEvent where
  parseJSON :: Value -> Parser CreateScheduledEvent
parseJSON =
    String
-> (Object -> Parser CreateScheduledEvent)
-> Value
-> Parser CreateScheduledEvent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CreateScheduledEvent" ((Object -> Parser CreateScheduledEvent)
 -> Value -> Parser CreateScheduledEvent)
-> (Object -> Parser CreateScheduledEvent)
-> Value
-> Parser CreateScheduledEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      InputWebhook
-> UTCTime
-> Maybe Value
-> [HeaderConf]
-> STRetryConf
-> Maybe Text
-> Maybe RequestTransform
-> Maybe MetadataResponseTransform
-> CreateScheduledEvent
CreateScheduledEvent (InputWebhook
 -> UTCTime
 -> Maybe Value
 -> [HeaderConf]
 -> STRetryConf
 -> Maybe Text
 -> Maybe RequestTransform
 -> Maybe MetadataResponseTransform
 -> CreateScheduledEvent)
-> Parser InputWebhook
-> Parser
     (UTCTime
      -> Maybe Value
      -> [HeaderConf]
      -> STRetryConf
      -> Maybe Text
      -> Maybe RequestTransform
      -> Maybe MetadataResponseTransform
      -> CreateScheduledEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser InputWebhook
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"webhook"
        Parser
  (UTCTime
   -> Maybe Value
   -> [HeaderConf]
   -> STRetryConf
   -> Maybe Text
   -> Maybe RequestTransform
   -> Maybe MetadataResponseTransform
   -> CreateScheduledEvent)
-> Parser UTCTime
-> Parser
     (Maybe Value
      -> [HeaderConf]
      -> STRetryConf
      -> Maybe Text
      -> Maybe RequestTransform
      -> Maybe MetadataResponseTransform
      -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"schedule_at"
        Parser
  (Maybe Value
   -> [HeaderConf]
   -> STRetryConf
   -> Maybe Text
   -> Maybe RequestTransform
   -> Maybe MetadataResponseTransform
   -> CreateScheduledEvent)
-> Parser (Maybe Value)
-> Parser
     ([HeaderConf]
      -> STRetryConf
      -> Maybe Text
      -> Maybe RequestTransform
      -> Maybe MetadataResponseTransform
      -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"payload"
        Parser
  ([HeaderConf]
   -> STRetryConf
   -> Maybe Text
   -> Maybe RequestTransform
   -> Maybe MetadataResponseTransform
   -> CreateScheduledEvent)
-> Parser [HeaderConf]
-> Parser
     (STRetryConf
      -> Maybe Text
      -> Maybe RequestTransform
      -> Maybe MetadataResponseTransform
      -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [HeaderConf])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"headers" Parser (Maybe [HeaderConf]) -> [HeaderConf] -> Parser [HeaderConf]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
        Parser
  (STRetryConf
   -> Maybe Text
   -> Maybe RequestTransform
   -> Maybe MetadataResponseTransform
   -> CreateScheduledEvent)
-> Parser STRetryConf
-> Parser
     (Maybe Text
      -> Maybe RequestTransform
      -> Maybe MetadataResponseTransform
      -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe STRetryConf)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_conf" Parser (Maybe STRetryConf) -> STRetryConf -> Parser STRetryConf
forall a. Parser (Maybe a) -> a -> Parser a
.!= STRetryConf
defaultSTRetryConf
        Parser
  (Maybe Text
   -> Maybe RequestTransform
   -> Maybe MetadataResponseTransform
   -> CreateScheduledEvent)
-> Parser (Maybe Text)
-> Parser
     (Maybe RequestTransform
      -> Maybe MetadataResponseTransform -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"comment"
        Parser
  (Maybe RequestTransform
   -> Maybe MetadataResponseTransform -> CreateScheduledEvent)
-> Parser (Maybe RequestTransform)
-> Parser (Maybe MetadataResponseTransform -> CreateScheduledEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe RequestTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"request_transform"
        Parser (Maybe MetadataResponseTransform -> CreateScheduledEvent)
-> Parser (Maybe MetadataResponseTransform)
-> Parser CreateScheduledEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe MetadataResponseTransform)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"response_transform"

$(deriveToJSON hasuraJSON ''CreateScheduledEvent)

-- | The 'ScheduledEventType' data type is needed to differentiate
--   between a 'CronScheduledEvent' and 'OneOffScheduledEvent' scheduled
--   event because they both have different configurations
--   and they live in different tables.
data ScheduledEventType
  = -- | A Cron scheduled event has a template defined which will
    -- contain the webhook, header configuration, retry
    -- configuration and a payload. Every cron event created
    -- uses the above mentioned configurations defined in the template.
    -- The configuration defined with the cron trigger is cached
    -- and hence it's not fetched along the cron scheduled events.
    Cron
  | -- | A One-off scheduled event doesn't have any template defined
    -- so all the configuration is fetched along the scheduled events.
    OneOff
  deriving (ScheduledEventType -> ScheduledEventType -> Bool
(ScheduledEventType -> ScheduledEventType -> Bool)
-> (ScheduledEventType -> ScheduledEventType -> Bool)
-> Eq ScheduledEventType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledEventType -> ScheduledEventType -> Bool
$c/= :: ScheduledEventType -> ScheduledEventType -> Bool
== :: ScheduledEventType -> ScheduledEventType -> Bool
$c== :: ScheduledEventType -> ScheduledEventType -> Bool
Eq, Int -> ScheduledEventType -> ShowS
[ScheduledEventType] -> ShowS
ScheduledEventType -> String
(Int -> ScheduledEventType -> ShowS)
-> (ScheduledEventType -> String)
-> ([ScheduledEventType] -> ShowS)
-> Show ScheduledEventType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledEventType] -> ShowS
$cshowList :: [ScheduledEventType] -> ShowS
show :: ScheduledEventType -> String
$cshow :: ScheduledEventType -> String
showsPrec :: Int -> ScheduledEventType -> ShowS
$cshowsPrec :: Int -> ScheduledEventType -> ShowS
Show)

$(deriveJSON defaultOptions {constructorTagModifier = snakeCase} ''ScheduledEventType)

data ScheduledEventInvocation = ScheduledEventInvocation
  { ScheduledEventInvocation -> Text
_seiId :: InvocationId,
    ScheduledEventInvocation -> EventId
_seiEventId :: EventId,
    ScheduledEventInvocation -> Maybe Int
_seiStatus :: Maybe Int,
    ScheduledEventInvocation -> Maybe Value
_seiRequest :: Maybe Value,
    ScheduledEventInvocation -> Maybe Value
_seiResponse :: Maybe Value,
    ScheduledEventInvocation -> UTCTime
_seiCreatedAt :: UTCTime
  }
  deriving (Int -> ScheduledEventInvocation -> ShowS
[ScheduledEventInvocation] -> ShowS
ScheduledEventInvocation -> String
(Int -> ScheduledEventInvocation -> ShowS)
-> (ScheduledEventInvocation -> String)
-> ([ScheduledEventInvocation] -> ShowS)
-> Show ScheduledEventInvocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledEventInvocation] -> ShowS
$cshowList :: [ScheduledEventInvocation] -> ShowS
show :: ScheduledEventInvocation -> String
$cshow :: ScheduledEventInvocation -> String
showsPrec :: Int -> ScheduledEventInvocation -> ShowS
$cshowsPrec :: Int -> ScheduledEventInvocation -> ShowS
Show, ScheduledEventInvocation -> ScheduledEventInvocation -> Bool
(ScheduledEventInvocation -> ScheduledEventInvocation -> Bool)
-> (ScheduledEventInvocation -> ScheduledEventInvocation -> Bool)
-> Eq ScheduledEventInvocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledEventInvocation -> ScheduledEventInvocation -> Bool
$c/= :: ScheduledEventInvocation -> ScheduledEventInvocation -> Bool
== :: ScheduledEventInvocation -> ScheduledEventInvocation -> Bool
$c== :: ScheduledEventInvocation -> ScheduledEventInvocation -> Bool
Eq)

$(deriveJSON hasuraJSON ''ScheduledEventInvocation)

data ScheduledEvent
  = SEOneOff
  | SECron TriggerName
  deriving (Int -> ScheduledEvent -> ShowS
[ScheduledEvent] -> ShowS
ScheduledEvent -> String
(Int -> ScheduledEvent -> ShowS)
-> (ScheduledEvent -> String)
-> ([ScheduledEvent] -> ShowS)
-> Show ScheduledEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledEvent] -> ShowS
$cshowList :: [ScheduledEvent] -> ShowS
show :: ScheduledEvent -> String
$cshow :: ScheduledEvent -> String
showsPrec :: Int -> ScheduledEvent -> ShowS
$cshowsPrec :: Int -> ScheduledEvent -> ShowS
Show, ScheduledEvent -> ScheduledEvent -> Bool
(ScheduledEvent -> ScheduledEvent -> Bool)
-> (ScheduledEvent -> ScheduledEvent -> Bool) -> Eq ScheduledEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledEvent -> ScheduledEvent -> Bool
$c/= :: ScheduledEvent -> ScheduledEvent -> Bool
== :: ScheduledEvent -> ScheduledEvent -> Bool
$c== :: ScheduledEvent -> ScheduledEvent -> Bool
Eq)

parseScheduledEvent :: Object -> Parser ScheduledEvent
parseScheduledEvent :: Object -> Parser ScheduledEvent
parseScheduledEvent Object
o = do
  ScheduledEventType
ty <- Object
o Object -> Key -> Parser ScheduledEventType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
  case ScheduledEventType
ty of
    ScheduledEventType
Cron -> TriggerName -> ScheduledEvent
SECron (TriggerName -> ScheduledEvent)
-> Parser TriggerName -> Parser ScheduledEvent
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser TriggerName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"trigger_name"
    ScheduledEventType
OneOff -> ScheduledEvent -> Parser ScheduledEvent
forall (f :: * -> *) a. Applicative f => a -> f a
pure ScheduledEvent
SEOneOff

scheduledEventToPairs :: ScheduledEvent -> [Pair]
scheduledEventToPairs :: ScheduledEvent -> [Pair]
scheduledEventToPairs = \case
  ScheduledEvent
SEOneOff -> [Key
"type" Key -> ScheduledEventType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ScheduledEventType
OneOff]
  SECron TriggerName
name -> [Key
"type" Key -> ScheduledEventType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ScheduledEventType
Cron, Key
"trigger_name" Key -> TriggerName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= TriggerName
name]

data CronEventSeed = CronEventSeed
  { CronEventSeed -> TriggerName
cesName :: TriggerName,
    CronEventSeed -> UTCTime
cesScheduledTime :: UTCTime
  }
  deriving (Int -> CronEventSeed -> ShowS
[CronEventSeed] -> ShowS
CronEventSeed -> String
(Int -> CronEventSeed -> ShowS)
-> (CronEventSeed -> String)
-> ([CronEventSeed] -> ShowS)
-> Show CronEventSeed
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CronEventSeed] -> ShowS
$cshowList :: [CronEventSeed] -> ShowS
show :: CronEventSeed -> String
$cshow :: CronEventSeed -> String
showsPrec :: Int -> CronEventSeed -> ShowS
$cshowsPrec :: Int -> CronEventSeed -> ShowS
Show, CronEventSeed -> CronEventSeed -> Bool
(CronEventSeed -> CronEventSeed -> Bool)
-> (CronEventSeed -> CronEventSeed -> Bool) -> Eq CronEventSeed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CronEventSeed -> CronEventSeed -> Bool
$c/= :: CronEventSeed -> CronEventSeed -> Bool
== :: CronEventSeed -> CronEventSeed -> Bool
$c== :: CronEventSeed -> CronEventSeed -> Bool
Eq)

type OneOffEvent = CreateScheduledEvent

data ScheduledEventStatus
  = SESScheduled
  | SESLocked
  | SESDelivered
  | SESError
  | SESDead
  deriving (Int -> ScheduledEventStatus -> ShowS
[ScheduledEventStatus] -> ShowS
ScheduledEventStatus -> String
(Int -> ScheduledEventStatus -> ShowS)
-> (ScheduledEventStatus -> String)
-> ([ScheduledEventStatus] -> ShowS)
-> Show ScheduledEventStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledEventStatus] -> ShowS
$cshowList :: [ScheduledEventStatus] -> ShowS
show :: ScheduledEventStatus -> String
$cshow :: ScheduledEventStatus -> String
showsPrec :: Int -> ScheduledEventStatus -> ShowS
$cshowsPrec :: Int -> ScheduledEventStatus -> ShowS
Show, ScheduledEventStatus -> ScheduledEventStatus -> Bool
(ScheduledEventStatus -> ScheduledEventStatus -> Bool)
-> (ScheduledEventStatus -> ScheduledEventStatus -> Bool)
-> Eq ScheduledEventStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledEventStatus -> ScheduledEventStatus -> Bool
$c/= :: ScheduledEventStatus -> ScheduledEventStatus -> Bool
== :: ScheduledEventStatus -> ScheduledEventStatus -> Bool
$c== :: ScheduledEventStatus -> ScheduledEventStatus -> Bool
Eq)

scheduledEventStatusToText :: ScheduledEventStatus -> Text
scheduledEventStatusToText :: ScheduledEventStatus -> Text
scheduledEventStatusToText ScheduledEventStatus
SESScheduled = Text
"scheduled"
scheduledEventStatusToText ScheduledEventStatus
SESLocked = Text
"locked"
scheduledEventStatusToText ScheduledEventStatus
SESDelivered = Text
"delivered"
scheduledEventStatusToText ScheduledEventStatus
SESError = Text
"error"
scheduledEventStatusToText ScheduledEventStatus
SESDead = Text
"dead"

textToScheduledEventStatus :: Text -> Maybe ScheduledEventStatus
textToScheduledEventStatus :: Text -> Maybe ScheduledEventStatus
textToScheduledEventStatus = \case
  Text
"scheduled" -> ScheduledEventStatus -> Maybe ScheduledEventStatus
forall a. a -> Maybe a
Just ScheduledEventStatus
SESScheduled
  Text
"locked" -> ScheduledEventStatus -> Maybe ScheduledEventStatus
forall a. a -> Maybe a
Just ScheduledEventStatus
SESLocked
  Text
"delivered" -> ScheduledEventStatus -> Maybe ScheduledEventStatus
forall a. a -> Maybe a
Just ScheduledEventStatus
SESDelivered
  Text
"error" -> ScheduledEventStatus -> Maybe ScheduledEventStatus
forall a. a -> Maybe a
Just ScheduledEventStatus
SESError
  Text
"dead" -> ScheduledEventStatus -> Maybe ScheduledEventStatus
forall a. a -> Maybe a
Just ScheduledEventStatus
SESDead
  Text
_ -> Maybe ScheduledEventStatus
forall a. Maybe a
Nothing

instance Q.ToPrepArg ScheduledEventStatus where
  toPrepVal :: ScheduledEventStatus -> PrepArg
toPrepVal = Text -> PrepArg
forall a. ToPrepArg a => a -> PrepArg
Q.toPrepVal (Text -> PrepArg)
-> (ScheduledEventStatus -> Text)
-> ScheduledEventStatus
-> PrepArg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScheduledEventStatus -> Text
scheduledEventStatusToText

instance Q.FromCol ScheduledEventStatus where
  fromCol :: Maybe ByteString -> Either Text ScheduledEventStatus
fromCol Maybe ByteString
bs =
    (Value ScheduledEventStatus
 -> Maybe ByteString -> Either Text ScheduledEventStatus)
-> Maybe ByteString
-> Value ScheduledEventStatus
-> Either Text ScheduledEventStatus
forall a b c. (a -> b -> c) -> b -> a -> c
flip Value ScheduledEventStatus
-> Maybe ByteString -> Either Text ScheduledEventStatus
forall a. Value a -> Maybe ByteString -> Either Text a
Q.fromColHelper Maybe ByteString
bs (Value ScheduledEventStatus -> Either Text ScheduledEventStatus)
-> Value ScheduledEventStatus -> Either Text ScheduledEventStatus
forall a b. (a -> b) -> a -> b
$ (Text -> Maybe ScheduledEventStatus) -> Value ScheduledEventStatus
forall a. (Text -> Maybe a) -> Value a
PD.enum Text -> Maybe ScheduledEventStatus
textToScheduledEventStatus

instance ToJSON ScheduledEventStatus where
  toJSON :: ScheduledEventStatus -> Value
toJSON = Text -> Value
String (Text -> Value)
-> (ScheduledEventStatus -> Text) -> ScheduledEventStatus -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScheduledEventStatus -> Text
scheduledEventStatusToText

instance FromJSON ScheduledEventStatus where
  parseJSON :: Value -> Parser ScheduledEventStatus
parseJSON = String
-> (Text -> Parser ScheduledEventStatus)
-> Value
-> Parser ScheduledEventStatus
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"String" ((Text -> Parser ScheduledEventStatus)
 -> Value -> Parser ScheduledEventStatus)
-> (Text -> Parser ScheduledEventStatus)
-> Value
-> Parser ScheduledEventStatus
forall a b. (a -> b) -> a -> b
$ \Text
s ->
    Maybe ScheduledEventStatus
-> Parser ScheduledEventStatus -> Parser ScheduledEventStatus
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
onNothing (Text -> Maybe ScheduledEventStatus
textToScheduledEventStatus Text
s) (Parser ScheduledEventStatus -> Parser ScheduledEventStatus)
-> Parser ScheduledEventStatus -> Parser ScheduledEventStatus
forall a b. (a -> b) -> a -> b
$
      String -> Parser ScheduledEventStatus
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ScheduledEventStatus)
-> String -> Parser ScheduledEventStatus
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Text
"unexpected status: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
s

data OneOffScheduledEvent = OneOffScheduledEvent
  { OneOffScheduledEvent -> EventId
_ooseId :: OneOffScheduledEventId,
    OneOffScheduledEvent -> InputWebhook
_ooseWebhookConf :: InputWebhook,
    OneOffScheduledEvent -> UTCTime
_ooseScheduledTime :: UTCTime,
    OneOffScheduledEvent -> STRetryConf
_ooseRetryConf :: STRetryConf,
    OneOffScheduledEvent -> Maybe Value
_oosePayload :: Maybe Value,
    OneOffScheduledEvent -> [HeaderConf]
_ooseHeaderConf :: [HeaderConf],
    OneOffScheduledEvent -> Text
_ooseStatus :: Text,
    OneOffScheduledEvent -> Int
_ooseTries :: Int,
    OneOffScheduledEvent -> UTCTime
_ooseCreatedAt :: UTCTime,
    OneOffScheduledEvent -> Maybe UTCTime
_ooseNextRetryAt :: Maybe UTCTime,
    OneOffScheduledEvent -> Maybe Text
_ooseComment :: Maybe Text,
    OneOffScheduledEvent -> Maybe RequestTransform
_ooseRequestTransform :: Maybe RequestTransform,
    OneOffScheduledEvent -> Maybe MetadataResponseTransform
_ooseResponseTransform :: Maybe MetadataResponseTransform
  }
  deriving (Int -> OneOffScheduledEvent -> ShowS
[OneOffScheduledEvent] -> ShowS
OneOffScheduledEvent -> String
(Int -> OneOffScheduledEvent -> ShowS)
-> (OneOffScheduledEvent -> String)
-> ([OneOffScheduledEvent] -> ShowS)
-> Show OneOffScheduledEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OneOffScheduledEvent] -> ShowS
$cshowList :: [OneOffScheduledEvent] -> ShowS
show :: OneOffScheduledEvent -> String
$cshow :: OneOffScheduledEvent -> String
showsPrec :: Int -> OneOffScheduledEvent -> ShowS
$cshowsPrec :: Int -> OneOffScheduledEvent -> ShowS
Show, OneOffScheduledEvent -> OneOffScheduledEvent -> Bool
(OneOffScheduledEvent -> OneOffScheduledEvent -> Bool)
-> (OneOffScheduledEvent -> OneOffScheduledEvent -> Bool)
-> Eq OneOffScheduledEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OneOffScheduledEvent -> OneOffScheduledEvent -> Bool
$c/= :: OneOffScheduledEvent -> OneOffScheduledEvent -> Bool
== :: OneOffScheduledEvent -> OneOffScheduledEvent -> Bool
$c== :: OneOffScheduledEvent -> OneOffScheduledEvent -> Bool
Eq)

$(deriveJSON hasuraJSON ''OneOffScheduledEvent)

data CronEvent = CronEvent
  { CronEvent -> EventId
_ceId :: CronEventId,
    CronEvent -> TriggerName
_ceTriggerName :: TriggerName,
    -- | We expect this to always be at second zero, since cron events have
    -- minute resolution. Note that a OneOffScheduledEvent has full timestamp
    -- precision.
    CronEvent -> UTCTime
_ceScheduledTime :: UTCTime,
    CronEvent -> Text
_ceStatus :: Text,
    CronEvent -> Int
_ceTries :: Int,
    -- | it is the time at which the cron event generator created the event
    CronEvent -> UTCTime
_ceCreatedAt :: UTCTime,
    CronEvent -> Maybe UTCTime
_ceNextRetryAt :: Maybe UTCTime
  }
  deriving (Int -> CronEvent -> ShowS
[CronEvent] -> ShowS
CronEvent -> String
(Int -> CronEvent -> ShowS)
-> (CronEvent -> String)
-> ([CronEvent] -> ShowS)
-> Show CronEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CronEvent] -> ShowS
$cshowList :: [CronEvent] -> ShowS
show :: CronEvent -> String
$cshow :: CronEvent -> String
showsPrec :: Int -> CronEvent -> ShowS
$cshowsPrec :: Int -> CronEvent -> ShowS
Show, CronEvent -> CronEvent -> Bool
(CronEvent -> CronEvent -> Bool)
-> (CronEvent -> CronEvent -> Bool) -> Eq CronEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CronEvent -> CronEvent -> Bool
$c/= :: CronEvent -> CronEvent -> Bool
== :: CronEvent -> CronEvent -> Bool
$c== :: CronEvent -> CronEvent -> Bool
Eq)

$(deriveJSON hasuraJSON ''CronEvent)

data ScheduledEventPagination = ScheduledEventPagination
  { ScheduledEventPagination -> Maybe Int
_sepLimit :: Maybe Int,
    ScheduledEventPagination -> Maybe Int
_sepOffset :: Maybe Int
  }
  deriving (Int -> ScheduledEventPagination -> ShowS
[ScheduledEventPagination] -> ShowS
ScheduledEventPagination -> String
(Int -> ScheduledEventPagination -> ShowS)
-> (ScheduledEventPagination -> String)
-> ([ScheduledEventPagination] -> ShowS)
-> Show ScheduledEventPagination
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScheduledEventPagination] -> ShowS
$cshowList :: [ScheduledEventPagination] -> ShowS
show :: ScheduledEventPagination -> String
$cshow :: ScheduledEventPagination -> String
showsPrec :: Int -> ScheduledEventPagination -> ShowS
$cshowsPrec :: Int -> ScheduledEventPagination -> ShowS
Show, ScheduledEventPagination -> ScheduledEventPagination -> Bool
(ScheduledEventPagination -> ScheduledEventPagination -> Bool)
-> (ScheduledEventPagination -> ScheduledEventPagination -> Bool)
-> Eq ScheduledEventPagination
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduledEventPagination -> ScheduledEventPagination -> Bool
$c/= :: ScheduledEventPagination -> ScheduledEventPagination -> Bool
== :: ScheduledEventPagination -> ScheduledEventPagination -> Bool
$c== :: ScheduledEventPagination -> ScheduledEventPagination -> Bool
Eq)

parseScheduledEventPagination :: Object -> Parser ScheduledEventPagination
parseScheduledEventPagination :: Object -> Parser ScheduledEventPagination
parseScheduledEventPagination Object
o =
  Maybe Int -> Maybe Int -> ScheduledEventPagination
ScheduledEventPagination
    (Maybe Int -> Maybe Int -> ScheduledEventPagination)
-> Parser (Maybe Int)
-> Parser (Maybe Int -> ScheduledEventPagination)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"limit"
    Parser (Maybe Int -> ScheduledEventPagination)
-> Parser (Maybe Int) -> Parser ScheduledEventPagination
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"offset"

scheduledEventPaginationToPairs :: ScheduledEventPagination -> [Pair]
scheduledEventPaginationToPairs :: ScheduledEventPagination -> [Pair]
scheduledEventPaginationToPairs ScheduledEventPagination {Maybe Int
_sepOffset :: Maybe Int
_sepLimit :: Maybe Int
_sepOffset :: ScheduledEventPagination -> Maybe Int
_sepLimit :: ScheduledEventPagination -> Maybe Int
..} =
  [Key
"limit" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
_sepLimit, Key
"offset" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
_sepOffset]

-- | Query type to fetch all one-off/cron scheduled events
data GetScheduledEvents = GetScheduledEvents
  { GetScheduledEvents -> ScheduledEvent
_gseScheduledEvent :: ScheduledEvent,
    GetScheduledEvents -> ScheduledEventPagination
_gsePagination :: ScheduledEventPagination,
    GetScheduledEvents -> [ScheduledEventStatus]
_gseStatus :: [ScheduledEventStatus]
  }
  deriving (Int -> GetScheduledEvents -> ShowS
[GetScheduledEvents] -> ShowS
GetScheduledEvents -> String
(Int -> GetScheduledEvents -> ShowS)
-> (GetScheduledEvents -> String)
-> ([GetScheduledEvents] -> ShowS)
-> Show GetScheduledEvents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetScheduledEvents] -> ShowS
$cshowList :: [GetScheduledEvents] -> ShowS
show :: GetScheduledEvents -> String
$cshow :: GetScheduledEvents -> String
showsPrec :: Int -> GetScheduledEvents -> ShowS
$cshowsPrec :: Int -> GetScheduledEvents -> ShowS
Show, GetScheduledEvents -> GetScheduledEvents -> Bool
(GetScheduledEvents -> GetScheduledEvents -> Bool)
-> (GetScheduledEvents -> GetScheduledEvents -> Bool)
-> Eq GetScheduledEvents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetScheduledEvents -> GetScheduledEvents -> Bool
$c/= :: GetScheduledEvents -> GetScheduledEvents -> Bool
== :: GetScheduledEvents -> GetScheduledEvents -> Bool
$c== :: GetScheduledEvents -> GetScheduledEvents -> Bool
Eq)

instance ToJSON GetScheduledEvents where
  toJSON :: GetScheduledEvents -> Value
toJSON GetScheduledEvents {[ScheduledEventStatus]
ScheduledEvent
ScheduledEventPagination
_gseStatus :: [ScheduledEventStatus]
_gsePagination :: ScheduledEventPagination
_gseScheduledEvent :: ScheduledEvent
_gseStatus :: GetScheduledEvents -> [ScheduledEventStatus]
_gsePagination :: GetScheduledEvents -> ScheduledEventPagination
_gseScheduledEvent :: GetScheduledEvents -> ScheduledEvent
..} =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      ScheduledEvent -> [Pair]
scheduledEventToPairs ScheduledEvent
_gseScheduledEvent
        [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> ScheduledEventPagination -> [Pair]
scheduledEventPaginationToPairs ScheduledEventPagination
_gsePagination
        [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Key
"status" Key -> [ScheduledEventStatus] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [ScheduledEventStatus]
_gseStatus]

instance FromJSON GetScheduledEvents where
  parseJSON :: Value -> Parser GetScheduledEvents
parseJSON = String
-> (Object -> Parser GetScheduledEvents)
-> Value
-> Parser GetScheduledEvents
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Object" ((Object -> Parser GetScheduledEvents)
 -> Value -> Parser GetScheduledEvents)
-> (Object -> Parser GetScheduledEvents)
-> Value
-> Parser GetScheduledEvents
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    ScheduledEvent
-> ScheduledEventPagination
-> [ScheduledEventStatus]
-> GetScheduledEvents
GetScheduledEvents
      (ScheduledEvent
 -> ScheduledEventPagination
 -> [ScheduledEventStatus]
 -> GetScheduledEvents)
-> Parser ScheduledEvent
-> Parser
     (ScheduledEventPagination
      -> [ScheduledEventStatus] -> GetScheduledEvents)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser ScheduledEvent
parseScheduledEvent Object
o
      Parser
  (ScheduledEventPagination
   -> [ScheduledEventStatus] -> GetScheduledEvents)
-> Parser ScheduledEventPagination
-> Parser ([ScheduledEventStatus] -> GetScheduledEvents)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser ScheduledEventPagination
parseScheduledEventPagination Object
o
      Parser ([ScheduledEventStatus] -> GetScheduledEvents)
-> Parser [ScheduledEventStatus] -> Parser GetScheduledEvents
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe [ScheduledEventStatus])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"status" Parser (Maybe [ScheduledEventStatus])
-> [ScheduledEventStatus] -> Parser [ScheduledEventStatus]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []

data WithTotalCount a = WithTotalCount
  { WithTotalCount a -> Int
_wtcCount :: Int,
    WithTotalCount a -> a
_wtcData :: a
  }
  deriving (Int -> WithTotalCount a -> ShowS
[WithTotalCount a] -> ShowS
WithTotalCount a -> String
(Int -> WithTotalCount a -> ShowS)
-> (WithTotalCount a -> String)
-> ([WithTotalCount a] -> ShowS)
-> Show (WithTotalCount a)
forall a. Show a => Int -> WithTotalCount a -> ShowS
forall a. Show a => [WithTotalCount a] -> ShowS
forall a. Show a => WithTotalCount a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithTotalCount a] -> ShowS
$cshowList :: forall a. Show a => [WithTotalCount a] -> ShowS
show :: WithTotalCount a -> String
$cshow :: forall a. Show a => WithTotalCount a -> String
showsPrec :: Int -> WithTotalCount a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithTotalCount a -> ShowS
Show, WithTotalCount a -> WithTotalCount a -> Bool
(WithTotalCount a -> WithTotalCount a -> Bool)
-> (WithTotalCount a -> WithTotalCount a -> Bool)
-> Eq (WithTotalCount a)
forall a. Eq a => WithTotalCount a -> WithTotalCount a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithTotalCount a -> WithTotalCount a -> Bool
$c/= :: forall a. Eq a => WithTotalCount a -> WithTotalCount a -> Bool
== :: WithTotalCount a -> WithTotalCount a -> Bool
$c== :: forall a. Eq a => WithTotalCount a -> WithTotalCount a -> Bool
Eq)

-- | Query type to delete cron/one-off events.
data DeleteScheduledEvent = DeleteScheduledEvent
  { DeleteScheduledEvent -> ScheduledEventType
_dseType :: ScheduledEventType,
    DeleteScheduledEvent -> EventId
_dseEventId :: ScheduledEventId
  }
  deriving (Int -> DeleteScheduledEvent -> ShowS
[DeleteScheduledEvent] -> ShowS
DeleteScheduledEvent -> String
(Int -> DeleteScheduledEvent -> ShowS)
-> (DeleteScheduledEvent -> String)
-> ([DeleteScheduledEvent] -> ShowS)
-> Show DeleteScheduledEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteScheduledEvent] -> ShowS
$cshowList :: [DeleteScheduledEvent] -> ShowS
show :: DeleteScheduledEvent -> String
$cshow :: DeleteScheduledEvent -> String
showsPrec :: Int -> DeleteScheduledEvent -> ShowS
$cshowsPrec :: Int -> DeleteScheduledEvent -> ShowS
Show, DeleteScheduledEvent -> DeleteScheduledEvent -> Bool
(DeleteScheduledEvent -> DeleteScheduledEvent -> Bool)
-> (DeleteScheduledEvent -> DeleteScheduledEvent -> Bool)
-> Eq DeleteScheduledEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteScheduledEvent -> DeleteScheduledEvent -> Bool
$c/= :: DeleteScheduledEvent -> DeleteScheduledEvent -> Bool
== :: DeleteScheduledEvent -> DeleteScheduledEvent -> Bool
$c== :: DeleteScheduledEvent -> DeleteScheduledEvent -> Bool
Eq)

$(deriveJSON hasuraJSON ''DeleteScheduledEvent)

data GetInvocationsBy
  = GIBEventId EventId ScheduledEventType
  | GIBEvent ScheduledEvent
  deriving (Int -> GetInvocationsBy -> ShowS
[GetInvocationsBy] -> ShowS
GetInvocationsBy -> String
(Int -> GetInvocationsBy -> ShowS)
-> (GetInvocationsBy -> String)
-> ([GetInvocationsBy] -> ShowS)
-> Show GetInvocationsBy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetInvocationsBy] -> ShowS
$cshowList :: [GetInvocationsBy] -> ShowS
show :: GetInvocationsBy -> String
$cshow :: GetInvocationsBy -> String
showsPrec :: Int -> GetInvocationsBy -> ShowS
$cshowsPrec :: Int -> GetInvocationsBy -> ShowS
Show, GetInvocationsBy -> GetInvocationsBy -> Bool
(GetInvocationsBy -> GetInvocationsBy -> Bool)
-> (GetInvocationsBy -> GetInvocationsBy -> Bool)
-> Eq GetInvocationsBy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetInvocationsBy -> GetInvocationsBy -> Bool
$c/= :: GetInvocationsBy -> GetInvocationsBy -> Bool
== :: GetInvocationsBy -> GetInvocationsBy -> Bool
$c== :: GetInvocationsBy -> GetInvocationsBy -> Bool
Eq)

data GetEventInvocations = GetEventInvocations
  { GetEventInvocations -> GetInvocationsBy
_geiInvocationsBy :: GetInvocationsBy,
    GetEventInvocations -> ScheduledEventPagination
_geiPagination :: ScheduledEventPagination
  }
  deriving (GetEventInvocations -> GetEventInvocations -> Bool
(GetEventInvocations -> GetEventInvocations -> Bool)
-> (GetEventInvocations -> GetEventInvocations -> Bool)
-> Eq GetEventInvocations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEventInvocations -> GetEventInvocations -> Bool
$c/= :: GetEventInvocations -> GetEventInvocations -> Bool
== :: GetEventInvocations -> GetEventInvocations -> Bool
$c== :: GetEventInvocations -> GetEventInvocations -> Bool
Eq, Int -> GetEventInvocations -> ShowS
[GetEventInvocations] -> ShowS
GetEventInvocations -> String
(Int -> GetEventInvocations -> ShowS)
-> (GetEventInvocations -> String)
-> ([GetEventInvocations] -> ShowS)
-> Show GetEventInvocations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEventInvocations] -> ShowS
$cshowList :: [GetEventInvocations] -> ShowS
show :: GetEventInvocations -> String
$cshow :: GetEventInvocations -> String
showsPrec :: Int -> GetEventInvocations -> ShowS
$cshowsPrec :: Int -> GetEventInvocations -> ShowS
Show)

instance FromJSON GetEventInvocations where
  parseJSON :: Value -> Parser GetEventInvocations
parseJSON = String
-> (Object -> Parser GetEventInvocations)
-> Value
-> Parser GetEventInvocations
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Object" ((Object -> Parser GetEventInvocations)
 -> Value -> Parser GetEventInvocations)
-> (Object -> Parser GetEventInvocations)
-> Value
-> Parser GetEventInvocations
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    GetInvocationsBy -> ScheduledEventPagination -> GetEventInvocations
GetEventInvocations
      (GetInvocationsBy
 -> ScheduledEventPagination -> GetEventInvocations)
-> Parser GetInvocationsBy
-> Parser (ScheduledEventPagination -> GetEventInvocations)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> Parser GetInvocationsBy
parseEventId Object
o Parser GetInvocationsBy
-> Parser GetInvocationsBy -> Parser GetInvocationsBy
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ScheduledEvent -> GetInvocationsBy
GIBEvent (ScheduledEvent -> GetInvocationsBy)
-> Parser ScheduledEvent -> Parser GetInvocationsBy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser ScheduledEvent
parseScheduledEvent Object
o))
      Parser (ScheduledEventPagination -> GetEventInvocations)
-> Parser ScheduledEventPagination -> Parser GetEventInvocations
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser ScheduledEventPagination
parseScheduledEventPagination Object
o
    where
      parseEventId :: Object -> Parser GetInvocationsBy
parseEventId Object
o =
        EventId -> ScheduledEventType -> GetInvocationsBy
GIBEventId (EventId -> ScheduledEventType -> GetInvocationsBy)
-> Parser EventId
-> Parser (ScheduledEventType -> GetInvocationsBy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser EventId
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"event_id" Parser (ScheduledEventType -> GetInvocationsBy)
-> Parser ScheduledEventType -> Parser GetInvocationsBy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser ScheduledEventType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"

instance ToJSON GetEventInvocations where
  toJSON :: GetEventInvocations -> Value
toJSON GetEventInvocations {ScheduledEventPagination
GetInvocationsBy
_geiPagination :: ScheduledEventPagination
_geiInvocationsBy :: GetInvocationsBy
_geiPagination :: GetEventInvocations -> ScheduledEventPagination
_geiInvocationsBy :: GetEventInvocations -> GetInvocationsBy
..} =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      case GetInvocationsBy
_geiInvocationsBy of
        GIBEventId EventId
eventId ScheduledEventType
eventType -> [Key
"event_id" Key -> EventId -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= EventId
eventId, Key
"type" Key -> ScheduledEventType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ScheduledEventType
eventType]
        GIBEvent ScheduledEvent
event -> ScheduledEvent -> [Pair]
scheduledEventToPairs ScheduledEvent
event
        [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> ScheduledEventPagination -> [Pair]
scheduledEventPaginationToPairs ScheduledEventPagination
_geiPagination

data ClearCronEvents
  = -- | Used to delete the cron events only of the specified cron trigger
    SingleCronTrigger TriggerName
  | -- | Used to delete all the cron events of the cron triggers with `include_in_metadata: true`
    -- It is used in the case of the `replace_metadata` API
    MetadataCronTriggers [TriggerName]
  deriving (Int -> ClearCronEvents -> ShowS
[ClearCronEvents] -> ShowS
ClearCronEvents -> String
(Int -> ClearCronEvents -> ShowS)
-> (ClearCronEvents -> String)
-> ([ClearCronEvents] -> ShowS)
-> Show ClearCronEvents
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClearCronEvents] -> ShowS
$cshowList :: [ClearCronEvents] -> ShowS
show :: ClearCronEvents -> String
$cshow :: ClearCronEvents -> String
showsPrec :: Int -> ClearCronEvents -> ShowS
$cshowsPrec :: Int -> ClearCronEvents -> ShowS
Show, ClearCronEvents -> ClearCronEvents -> Bool
(ClearCronEvents -> ClearCronEvents -> Bool)
-> (ClearCronEvents -> ClearCronEvents -> Bool)
-> Eq ClearCronEvents
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClearCronEvents -> ClearCronEvents -> Bool
$c/= :: ClearCronEvents -> ClearCronEvents -> Bool
== :: ClearCronEvents -> ClearCronEvents -> Bool
$c== :: ClearCronEvents -> ClearCronEvents -> Bool
Eq)