{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}

module Shrun.Configuration.Data.Notify
  ( -- * NotifyInit
    NotifyActionsInit (..),

    -- * NotifyActive
    NotifyActionsActive (..),
    _NotifyActionsActiveCompleteAny,
    _NotifyActionsActiveStartAny,

    -- * Notify
    NotifyP (..),
    NotifyArgs,
    NotifyToml,
    NotifyMerged,
    NotificationEnv,
    mergeNotifications,
    toEnv,
  )
where

import Shrun.Configuration.Data.ConfigPhase
  ( ConfigPhase
      ( ConfigPhaseArgs,
        ConfigPhaseEnv,
        ConfigPhaseMerged,
        ConfigPhaseToml
      ),
    ConfigPhaseF,
    SwitchF,
  )
import Shrun.Configuration.Data.Notify.Action
  ( NotifyActionComplete,
    NotifyActionStartSwitch,
  )
import Shrun.Configuration.Data.Notify.System
  ( mergeNotifySystem,
    parseNotifySystem,
  )
import Shrun.Configuration.Data.Notify.Timeout
  ( notifyTimeoutDecoder,
    prettyNotifyTimeout,
  )
import Shrun.Configuration.Data.WithDisabled
  ( WithDisabled (Disabled, With),
    (<|?|>),
  )
import Shrun.Configuration.Data.WithDisabled qualified as WD
import Shrun.Configuration.Default (Default, def, (<.>))
import Shrun.Prelude
import Shrun.Utils qualified as Utils

-- See NOTE: [Args vs. Toml mandatory fields]

-- | Notify action is optional on Init since all of this is optional.
-- We do not need to specify any other phases since we switch to
-- NotifyActionsActive.
type NotifyActionCompleteF :: ConfigPhase -> Type
type family NotifyActionCompleteF p where
  NotifyActionCompleteF ConfigPhaseArgs = Maybe (WithDisabled NotifyActionComplete)
  NotifyActionCompleteF ConfigPhaseToml = Maybe (WithDisabled NotifyActionComplete)

-- | Initial notify action config.
data NotifyActionsInit p = MkNotifyActionsInit
  { forall (p :: ConfigPhase).
NotifyActionsInit p -> NotifyActionCompleteF p
complete :: NotifyActionCompleteF p,
    forall (p :: ConfigPhase).
NotifyActionsInit p -> SwitchF p NotifyActionStartSwitch
start :: SwitchF p NotifyActionStartSwitch
  }

instance
  ( k ~ A_Lens,
    a ~ NotifyActionCompleteF p,
    b ~ NotifyActionCompleteF p
  ) =>
  LabelOptic "complete" k (NotifyActionsInit p) (NotifyActionsInit p) a b
  where
  labelOptic :: Optic k NoIx (NotifyActionsInit p) (NotifyActionsInit p) a b
labelOptic =
    LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
-> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b
forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
 -> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b)
-> LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
-> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f (MkNotifyActionsInit NotifyActionCompleteF p
a1 SwitchF p NotifyActionStartSwitch
a2) ->
        (b -> NotifyActionsInit p) -> f b -> f (NotifyActionsInit p)
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> f a -> f b
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap
          (\b
b -> NotifyActionCompleteF p
-> SwitchF p NotifyActionStartSwitch -> NotifyActionsInit p
forall (p :: ConfigPhase).
NotifyActionCompleteF p
-> SwitchF p NotifyActionStartSwitch -> NotifyActionsInit p
MkNotifyActionsInit b
NotifyActionCompleteF p
b SwitchF p NotifyActionStartSwitch
a2)
          (a -> f b
f a
NotifyActionCompleteF p
a1)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ SwitchF p NotifyActionStartSwitch,
    b ~ SwitchF p NotifyActionStartSwitch
  ) =>
  LabelOptic "start" k (NotifyActionsInit p) (NotifyActionsInit p) a b
  where
  labelOptic :: Optic k NoIx (NotifyActionsInit p) (NotifyActionsInit p) a b
labelOptic =
    LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
-> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b
forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
 -> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b)
-> LensVL (NotifyActionsInit p) (NotifyActionsInit p) a b
-> Lens (NotifyActionsInit p) (NotifyActionsInit p) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f (MkNotifyActionsInit NotifyActionCompleteF p
a1 SwitchF p NotifyActionStartSwitch
a2) ->
        (b -> NotifyActionsInit p) -> f b -> f (NotifyActionsInit p)
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> f a -> f b
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap
          (\b
b -> NotifyActionCompleteF p
-> SwitchF p NotifyActionStartSwitch -> NotifyActionsInit p
forall (p :: ConfigPhase).
NotifyActionCompleteF p
-> SwitchF p NotifyActionStartSwitch -> NotifyActionsInit p
MkNotifyActionsInit NotifyActionCompleteF p
a1 b
SwitchF p NotifyActionStartSwitch
b)
          (a -> f b
f a
SwitchF p NotifyActionStartSwitch
a2)
  {-# INLINE labelOptic #-}

instance
  ( NotifyActionCompleteF p ~ Maybe (WithDisabled NotifyActionComplete),
    SwitchF p NotifyActionStartSwitch ~ Maybe NotifyActionStartSwitch
  ) =>
  Semigroup (NotifyActionsInit p)
  where
  NotifyActionsInit p
l <> :: NotifyActionsInit p -> NotifyActionsInit p -> NotifyActionsInit p
<> NotifyActionsInit p
r =
    MkNotifyActionsInit
      { complete :: NotifyActionCompleteF p
complete = NotifyActionsInit p
l NotifyActionsInit p
-> Optic'
     A_Lens
     NoIx
     (NotifyActionsInit p)
     (Maybe (WithDisabled NotifyActionComplete))
-> Maybe (WithDisabled NotifyActionComplete)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (NotifyActionsInit p)
  (Maybe (WithDisabled NotifyActionComplete))
#complete Maybe (WithDisabled NotifyActionComplete)
-> Maybe (WithDisabled NotifyActionComplete)
-> Maybe (WithDisabled NotifyActionComplete)
forall (a :: OpticKind). Maybe a -> Maybe a -> Maybe a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Alternative f =>
f a -> f a -> f a
<|> NotifyActionsInit p
r NotifyActionsInit p
-> Optic'
     A_Lens
     NoIx
     (NotifyActionsInit p)
     (Maybe (WithDisabled NotifyActionComplete))
-> Maybe (WithDisabled NotifyActionComplete)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (NotifyActionsInit p)
  (Maybe (WithDisabled NotifyActionComplete))
#complete,
        start :: SwitchF p NotifyActionStartSwitch
start = NotifyActionsInit p
l NotifyActionsInit p
-> Optic'
     A_Lens NoIx (NotifyActionsInit p) (Maybe NotifyActionStartSwitch)
-> Maybe NotifyActionStartSwitch
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (NotifyActionsInit p) (Maybe NotifyActionStartSwitch)
#start Maybe NotifyActionStartSwitch
-> Maybe NotifyActionStartSwitch -> Maybe NotifyActionStartSwitch
forall (a :: OpticKind). Maybe a -> Maybe a -> Maybe a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Alternative f =>
f a -> f a -> f a
<|> NotifyActionsInit p
r NotifyActionsInit p
-> Optic'
     A_Lens NoIx (NotifyActionsInit p) (Maybe NotifyActionStartSwitch)
-> Maybe NotifyActionStartSwitch
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (NotifyActionsInit p) (Maybe NotifyActionStartSwitch)
#start
      }

instance
  ( NotifyActionCompleteF p ~ Maybe (WithDisabled NotifyActionComplete),
    SwitchF p NotifyActionStartSwitch ~ Maybe NotifyActionStartSwitch
  ) =>
  Monoid (NotifyActionsInit p)
  where
  mempty :: NotifyActionsInit p
mempty =
    MkNotifyActionsInit
      { complete :: NotifyActionCompleteF p
complete = Maybe (WithDisabled NotifyActionComplete)
NotifyActionCompleteF p
forall (a :: OpticKind). Maybe a
Nothing,
        start :: SwitchF p NotifyActionStartSwitch
start = Maybe NotifyActionStartSwitch
SwitchF p NotifyActionStartSwitch
forall (a :: OpticKind). Maybe a
Nothing
      }

deriving stock instance Eq (NotifyActionsInit ConfigPhaseArgs)

deriving stock instance Show (NotifyActionsInit ConfigPhaseToml)

deriving stock instance Eq (NotifyActionsInit ConfigPhaseToml)

deriving stock instance Show (NotifyActionsInit ConfigPhaseArgs)

-- | Holds active notif actions. This is morally 'These', specialized
-- to our notify action use case.
data NotifyActionsActive
  = -- | Complete actions active.
    NotifyActionsActiveComplete NotifyActionComplete
  | -- | Start actions active.
    NotifyActionsActiveStart
  | -- | All actions active.
    NotifyActionsActiveAll NotifyActionComplete
  deriving stock (NotifyActionsActive -> NotifyActionsActive -> Bool
(NotifyActionsActive -> NotifyActionsActive -> Bool)
-> (NotifyActionsActive -> NotifyActionsActive -> Bool)
-> Eq NotifyActionsActive
forall (a :: OpticKind).
(a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NotifyActionsActive -> NotifyActionsActive -> Bool
== :: NotifyActionsActive -> NotifyActionsActive -> Bool
$c/= :: NotifyActionsActive -> NotifyActionsActive -> Bool
/= :: NotifyActionsActive -> NotifyActionsActive -> Bool
Eq, Int -> NotifyActionsActive -> ShowS
[NotifyActionsActive] -> ShowS
NotifyActionsActive -> String
(Int -> NotifyActionsActive -> ShowS)
-> (NotifyActionsActive -> String)
-> ([NotifyActionsActive] -> ShowS)
-> Show NotifyActionsActive
forall (a :: OpticKind).
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotifyActionsActive -> ShowS
showsPrec :: Int -> NotifyActionsActive -> ShowS
$cshow :: NotifyActionsActive -> String
show :: NotifyActionsActive -> String
$cshowList :: [NotifyActionsActive] -> ShowS
showList :: [NotifyActionsActive] -> ShowS
Show)

instance Pretty NotifyActionsActive where
  pretty :: forall (ann :: OpticKind). NotifyActionsActive -> Doc ann
pretty = \case
    NotifyActionsActiveComplete NotifyActionComplete
c ->
      [Doc ann] -> Doc ann
forall (ann :: OpticKind). [Doc ann] -> Doc ann
vcat
        [ Doc ann
"action-complete: " Doc ann -> Doc ann -> Doc ann
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> NotifyActionComplete -> Doc ann
forall (a :: OpticKind) (ann :: OpticKind).
Pretty a =>
a -> Doc ann
forall (ann :: OpticKind). NotifyActionComplete -> Doc ann
pretty NotifyActionComplete
c,
          Doc ann
"action-start: off"
        ]
    NotifyActionsActive
NotifyActionsActiveStart ->
      [Doc ann] -> Doc ann
forall (ann :: OpticKind). [Doc ann] -> Doc ann
vcat
        [ Doc ann
"action-complete: off",
          Doc ann
"action-start: on"
        ]
    NotifyActionsActiveAll NotifyActionComplete
c ->
      [Doc ann] -> Doc ann
forall (ann :: OpticKind). [Doc ann] -> Doc ann
vcat
        [ Doc ann
"action-complete: " Doc ann -> Doc ann -> Doc ann
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> NotifyActionComplete -> Doc ann
forall (a :: OpticKind) (ann :: OpticKind).
Pretty a =>
a -> Doc ann
forall (ann :: OpticKind). NotifyActionComplete -> Doc ann
pretty NotifyActionComplete
c,
          Doc ann
"action-start: on"
        ]

-- NOTE:
--
-- These optics do not exactly match the constructors because they are intended
-- to match several. I have not checked if this is lawful, but they are
-- useful, so whatever.

_NotifyActionsActiveCompleteAny :: AffineFold NotifyActionsActive NotifyActionComplete
_NotifyActionsActiveCompleteAny :: AffineFold NotifyActionsActive NotifyActionComplete
_NotifyActionsActiveCompleteAny = (NotifyActionsActive -> Maybe NotifyActionComplete)
-> AffineFold NotifyActionsActive NotifyActionComplete
forall (s :: OpticKind) (a :: OpticKind).
(s -> Maybe a) -> AffineFold s a
afolding ((NotifyActionsActive -> Maybe NotifyActionComplete)
 -> AffineFold NotifyActionsActive NotifyActionComplete)
-> (NotifyActionsActive -> Maybe NotifyActionComplete)
-> AffineFold NotifyActionsActive NotifyActionComplete
forall a b. (a -> b) -> a -> b
$ \case
  NotifyActionsActiveComplete NotifyActionComplete
x -> NotifyActionComplete -> Maybe NotifyActionComplete
forall (a :: OpticKind). a -> Maybe a
Just NotifyActionComplete
x
  NotifyActionsActive
NotifyActionsActiveStart -> Maybe NotifyActionComplete
forall (a :: OpticKind). Maybe a
Nothing
  NotifyActionsActiveAll NotifyActionComplete
x -> NotifyActionComplete -> Maybe NotifyActionComplete
forall (a :: OpticKind). a -> Maybe a
Just NotifyActionComplete
x
{-# INLINE _NotifyActionsActiveCompleteAny #-}

_NotifyActionsActiveStartAny :: AffineFold NotifyActionsActive ()
_NotifyActionsActiveStartAny :: AffineFold NotifyActionsActive ()
_NotifyActionsActiveStartAny = (NotifyActionsActive -> Maybe ())
-> AffineFold NotifyActionsActive ()
forall (s :: OpticKind) (a :: OpticKind).
(s -> Maybe a) -> AffineFold s a
afolding ((NotifyActionsActive -> Maybe ())
 -> AffineFold NotifyActionsActive ())
-> (NotifyActionsActive -> Maybe ())
-> AffineFold NotifyActionsActive ()
forall a b. (a -> b) -> a -> b
$ \case
  NotifyActionsActiveComplete NotifyActionComplete
_ -> Maybe ()
forall (a :: OpticKind). Maybe a
Nothing
  NotifyActionsActive
NotifyActionsActiveStart -> () -> Maybe ()
forall (a :: OpticKind). a -> Maybe a
Just ()
  NotifyActionsActiveAll NotifyActionComplete
_ -> () -> Maybe ()
forall (a :: OpticKind). a -> Maybe a
Just ()
{-# INLINE _NotifyActionsActiveStartAny #-}

type NotifyActionsF :: ConfigPhase -> Type
type family NotifyActionsF p where
  NotifyActionsF ConfigPhaseArgs = NotifyActionsInit ConfigPhaseArgs
  NotifyActionsF ConfigPhaseToml = NotifyActionsInit ConfigPhaseToml
  NotifyActionsF ConfigPhaseMerged = NotifyActionsActive
  NotifyActionsF ConfigPhaseEnv = NotifyActionsActive

type NotifySystemF :: ConfigPhase -> Type -> Type
type family NotifySystemF p r where
  NotifySystemF ConfigPhaseArgs _ = Maybe NotifySystem
  NotifySystemF ConfigPhaseToml _ = Maybe NotifySystem
  NotifySystemF ConfigPhaseMerged _ = NotifySystem
  NotifySystemF ConfigPhaseEnv r = r

-- | Holds notification config. We have an invariant that if the notify config
-- exists (i.e. is 'Just'), then at least one of actionComplete, actionStart
-- should be Just/True.
type NotifyP :: ConfigPhase -> Type -> Type
data NotifyP p r = MkNotifyP
  { -- | Notify actions.
    forall (p :: ConfigPhase) (r :: OpticKind).
NotifyP p r -> NotifyActionsF p
actions :: NotifyActionsF p,
    -- | The notification system to use.
    forall (p :: ConfigPhase) (r :: OpticKind).
NotifyP p r -> NotifySystemF p r
system :: NotifySystemF p r,
    -- | when to timeout successful notifications.
    forall (p :: ConfigPhase) (r :: OpticKind).
NotifyP p r -> ConfigPhaseF p NotifyTimeout
timeout :: ConfigPhaseF p NotifyTimeout
  }

instance
  ( k ~ A_Lens,
    a ~ NotifyActionsF p,
    b ~ NotifyActionsF p
  ) =>
  LabelOptic "actions" k (NotifyP p r) (NotifyP p r) a b
  where
  labelOptic :: Optic k NoIx (NotifyP p r) (NotifyP p r) a b
labelOptic =
    LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (NotifyP p r) (NotifyP p r) a b
 -> Lens (NotifyP p r) (NotifyP p r) a b)
-> LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f (MkNotifyP NotifyActionsF p
a1 NotifySystemF p r
a2 ConfigPhaseF p NotifyTimeout
a3) ->
        (b -> NotifyP p r) -> f b -> f (NotifyP p r)
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> f a -> f b
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap
          (\b
b -> NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
forall (p :: ConfigPhase) (r :: OpticKind).
NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
MkNotifyP b
NotifyActionsF p
b NotifySystemF p r
a2 ConfigPhaseF p NotifyTimeout
a3)
          (a -> f b
f a
NotifyActionsF p
a1)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ NotifySystemF p r,
    b ~ NotifySystemF p r
  ) =>
  LabelOptic "system" k (NotifyP p r) (NotifyP p r) a b
  where
  labelOptic :: Optic k NoIx (NotifyP p r) (NotifyP p r) a b
labelOptic =
    LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (NotifyP p r) (NotifyP p r) a b
 -> Lens (NotifyP p r) (NotifyP p r) a b)
-> LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f (MkNotifyP NotifyActionsF p
a1 NotifySystemF p r
a2 ConfigPhaseF p NotifyTimeout
a3) ->
        (b -> NotifyP p r) -> f b -> f (NotifyP p r)
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> f a -> f b
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap
          (\b
b -> NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
forall (p :: ConfigPhase) (r :: OpticKind).
NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
MkNotifyP NotifyActionsF p
a1 b
NotifySystemF p r
b ConfigPhaseF p NotifyTimeout
a3)
          (a -> f b
f a
NotifySystemF p r
a2)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ ConfigPhaseF p NotifyTimeout,
    b ~ ConfigPhaseF p NotifyTimeout
  ) =>
  LabelOptic "timeout" k (NotifyP p r) (NotifyP p r) a b
  where
  labelOptic :: Optic k NoIx (NotifyP p r) (NotifyP p r) a b
labelOptic =
    LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL
      (LensVL (NotifyP p r) (NotifyP p r) a b
 -> Lens (NotifyP p r) (NotifyP p r) a b)
-> LensVL (NotifyP p r) (NotifyP p r) a b
-> Lens (NotifyP p r) (NotifyP p r) a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f (MkNotifyP NotifyActionsF p
a1 NotifySystemF p r
a2 ConfigPhaseF p NotifyTimeout
a3) ->
        (b -> NotifyP p r) -> f b -> f (NotifyP p r)
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> f a -> f b
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
fmap
          (\b
b -> NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
forall (p :: ConfigPhase) (r :: OpticKind).
NotifyActionsF p
-> NotifySystemF p r -> ConfigPhaseF p NotifyTimeout -> NotifyP p r
MkNotifyP NotifyActionsF p
a1 NotifySystemF p r
a2 b
ConfigPhaseF p NotifyTimeout
b)
          (a -> f b
f a
ConfigPhaseF p NotifyTimeout
a3)
  {-# INLINE labelOptic #-}

instance Semigroup (NotifyToml r) where
  NotifyToml r
l <> :: NotifyToml r -> NotifyToml r -> NotifyToml r
<> NotifyToml r
r =
    MkNotifyP
      { actions :: NotifyActionsF 'ConfigPhaseToml
actions = NotifyToml r
l NotifyToml r
-> Optic'
     A_Lens NoIx (NotifyToml r) (NotifyActionsInit 'ConfigPhaseToml)
-> NotifyActionsInit 'ConfigPhaseToml
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (NotifyToml r) (NotifyActionsInit 'ConfigPhaseToml)
#actions NotifyActionsInit 'ConfigPhaseToml
-> NotifyActionsInit 'ConfigPhaseToml
-> NotifyActionsInit 'ConfigPhaseToml
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> NotifyToml r
r NotifyToml r
-> Optic'
     A_Lens NoIx (NotifyToml r) (NotifyActionsInit 'ConfigPhaseToml)
-> NotifyActionsInit 'ConfigPhaseToml
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens NoIx (NotifyToml r) (NotifyActionsInit 'ConfigPhaseToml)
#actions,
        system :: NotifySystemF 'ConfigPhaseToml r
system = NotifyToml r
l NotifyToml r
-> Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifySystem)
-> Maybe NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifySystem)
#system Maybe NotifySystem -> Maybe NotifySystem -> Maybe NotifySystem
forall (a :: OpticKind). Maybe a -> Maybe a -> Maybe a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Alternative f =>
f a -> f a -> f a
<|> NotifyToml r
r NotifyToml r
-> Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifySystem)
-> Maybe NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifySystem)
#system,
        timeout :: ConfigPhaseF 'ConfigPhaseToml NotifyTimeout
timeout = NotifyToml r
l NotifyToml r
-> Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifyTimeout)
-> Maybe NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifyTimeout)
#timeout Maybe NotifyTimeout -> Maybe NotifyTimeout -> Maybe NotifyTimeout
forall (a :: OpticKind). Maybe a -> Maybe a -> Maybe a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Alternative f =>
f a -> f a -> f a
<|> NotifyToml r
r NotifyToml r
-> Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifyTimeout)
-> Maybe NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyToml r) (Maybe NotifyTimeout)
#timeout
      }

instance Monoid (NotifyToml r) where
  mempty :: NotifyToml r
mempty =
    MkNotifyP
      { actions :: NotifyActionsF 'ConfigPhaseToml
actions = NotifyActionsF 'ConfigPhaseToml
NotifyActionsInit 'ConfigPhaseToml
forall (a :: OpticKind). Monoid a => a
mempty,
        system :: NotifySystemF 'ConfigPhaseToml r
system = Maybe NotifySystem
NotifySystemF 'ConfigPhaseToml r
forall (a :: OpticKind). Maybe a
Nothing,
        timeout :: ConfigPhaseF 'ConfigPhaseToml NotifyTimeout
timeout = Maybe NotifyTimeout
ConfigPhaseF 'ConfigPhaseToml NotifyTimeout
forall (a :: OpticKind). Maybe a
Nothing
      }

instance Pretty (NotifyMerged r) where
  pretty :: forall (ann :: OpticKind). NotifyMerged r -> Doc ann
pretty NotifyMerged r
c =
    [Doc ann] -> Doc ann
forall (ann :: OpticKind). [Doc ann] -> Doc ann
vcat
      [ NotifyActionsActive -> Doc ann
forall (a :: OpticKind) (ann :: OpticKind).
Pretty a =>
a -> Doc ann
forall (ann :: OpticKind). NotifyActionsActive -> Doc ann
pretty (NotifyMerged r
c NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifyActionsActive
-> NotifyActionsActive
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifyActionsActive
#actions),
        Doc ann
"system: " Doc ann -> Doc ann -> Doc ann
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> Text -> Doc ann
forall (ann :: OpticKind). Text -> Doc ann
forall (a :: OpticKind) (ann :: OpticKind).
Pretty a =>
a -> Doc ann
pretty (NotifySystem -> Text
forall (a :: OpticKind). Display a => a -> Text
display (NotifySystem -> Text) -> NotifySystem -> Text
forall a b. (a -> b) -> a -> b
$ NotifyMerged r
c NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifySystem -> NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifySystem
#system),
        Doc ann
"timeout: " Doc ann -> Doc ann -> Doc ann
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> NotifyTimeout -> Doc ann
forall (ann :: OpticKind). NotifyTimeout -> Doc ann
prettyNotifyTimeout (NotifyMerged r
c NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifyTimeout
-> NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifyTimeout
#timeout)
      ]

type NotifyArgs = NotifyP ConfigPhaseArgs

type NotifyToml = NotifyP ConfigPhaseToml

type NotifyMerged = NotifyP ConfigPhaseMerged

-- Named NotificationEnv vs NotifyEnv to avoid clash with effects-notify.
type NotificationEnv = NotifyP ConfigPhaseEnv

deriving stock instance Eq (NotifyP ConfigPhaseArgs r)

deriving stock instance Show (NotifyP ConfigPhaseArgs r)

deriving stock instance Eq (NotifyP ConfigPhaseToml r)

deriving stock instance Show (NotifyP ConfigPhaseToml r)

deriving stock instance Eq (NotifyP ConfigPhaseMerged r)

deriving stock instance Show (NotifyP ConfigPhaseMerged r)

-- Only Default instance is for Args, since others require the action.
instance Default (NotifyArgs r) where
  def :: NotifyArgs r
def =
    MkNotifyP
      { actions :: NotifyActionsF 'ConfigPhaseArgs
actions = NotifyActionsF 'ConfigPhaseArgs
NotifyActionsInit 'ConfigPhaseArgs
forall (a :: OpticKind). Monoid a => a
mempty,
        system :: NotifySystemF 'ConfigPhaseArgs r
system = Maybe NotifySystem
NotifySystemF 'ConfigPhaseArgs r
forall (a :: OpticKind). Maybe a
Nothing,
        timeout :: ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
timeout = Maybe NotifyTimeout
ConfigPhaseF 'ConfigPhaseArgs NotifyTimeout
forall (a :: OpticKind). Maybe a
Nothing
      }

-- | Merges args and toml configs.
mergeNotifications ::
  NotifyArgs r ->
  Maybe (NotifyToml r) ->
  Maybe (NotifyMerged r)
mergeNotifications :: forall (r :: OpticKind).
NotifyArgs r -> Maybe (NotifyToml r) -> Maybe (NotifyMerged r)
mergeNotifications NotifyArgs r
args Maybe (NotifyToml r)
mToml = do
  case Maybe NotifyActionsActive
mActions of
    Maybe NotifyActionsActive
Nothing -> Maybe (NotifyMerged r)
forall (a :: OpticKind). Maybe a
Nothing
    Just NotifyActionsActive
actions -> do
      -- Also, no need to do this unless we are actually running with
      -- notifications.
      let system :: NotifySystem
system = Maybe NotifySystem -> Maybe NotifySystem -> NotifySystem
mergeNotifySystem (NotifyArgs r
args NotifyArgs r
-> Optic' A_Lens NoIx (NotifyArgs r) (Maybe NotifySystem)
-> Maybe NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyArgs r) (Maybe NotifySystem)
#system) (Maybe (NotifyToml r)
mToml Maybe (NotifyToml r)
-> Optic'
     An_AffineTraversal NoIx (Maybe (NotifyToml r)) NotifySystem
-> Maybe NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe NotifySystem)
  (Maybe NotifySystem)
-> Optic'
     An_AffineTraversal NoIx (Maybe (NotifyToml r)) NotifySystem
forall (k :: OpticKind) (m :: OpticKind) (l :: OpticKind)
       (ks :: IxList) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k A_Prism m, JoinKinds A_Prism l k) =>
Optic l ks u v (Maybe a) (Maybe b)
-> Optic m ks (Maybe u) (Maybe v) a b
Utils.surroundJust Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe NotifySystem)
  (Maybe NotifySystem)
#system)
      NotifyMerged r -> Maybe (NotifyMerged r)
forall (a :: OpticKind). a -> Maybe a
Just
        (NotifyMerged r -> Maybe (NotifyMerged r))
-> NotifyMerged r -> Maybe (NotifyMerged r)
forall a b. (a -> b) -> a -> b
$ MkNotifyP
          { NotifyActionsF 'ConfigPhaseMerged
NotifyActionsActive
actions :: NotifyActionsF 'ConfigPhaseMerged
actions :: NotifyActionsActive
actions,
            NotifySystem
NotifySystemF 'ConfigPhaseMerged r
system :: NotifySystemF 'ConfigPhaseMerged r
system :: NotifySystem
system,
            timeout :: ConfigPhaseF 'ConfigPhaseMerged NotifyTimeout
timeout =
              (NotifyArgs r
args NotifyArgs r
-> Optic' A_Lens NoIx (NotifyArgs r) (Maybe NotifyTimeout)
-> Maybe NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyArgs r) (Maybe NotifyTimeout)
#timeout) Maybe NotifyTimeout -> Maybe NotifyTimeout -> NotifyTimeout
forall (a :: OpticKind). Default a => Maybe a -> Maybe a -> a
<.> (Maybe (NotifyToml r)
mToml Maybe (NotifyToml r)
-> Optic'
     An_AffineTraversal NoIx (Maybe (NotifyToml r)) NotifyTimeout
-> Maybe NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe NotifyTimeout)
  (Maybe NotifyTimeout)
-> Optic'
     An_AffineTraversal NoIx (Maybe (NotifyToml r)) NotifyTimeout
forall (k :: OpticKind) (m :: OpticKind) (l :: OpticKind)
       (ks :: IxList) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k A_Prism m, JoinKinds A_Prism l k) =>
Optic l ks u v (Maybe a) (Maybe b)
-> Optic m ks (Maybe u) (Maybe v) a b
Utils.surroundJust Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe NotifyTimeout)
  (Maybe NotifyTimeout)
#timeout)
          }
  where
    mActionComplete :: Maybe NotifyActionComplete
    mActionComplete :: Maybe NotifyActionComplete
mActionComplete =
      NotifyArgs r
args NotifyArgs r
-> Optic'
     A_Lens
     NoIx
     (NotifyArgs r)
     (Maybe (WithDisabled NotifyActionComplete))
-> Maybe (WithDisabled NotifyActionComplete)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  (NotifyArgs r)
  (NotifyArgs r)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
#actions Optic
  A_Lens
  NoIx
  (NotifyArgs r)
  (NotifyArgs r)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
-> Optic
     A_Lens
     NoIx
     (NotifyActionsInit 'ConfigPhaseArgs)
     (NotifyActionsInit 'ConfigPhaseArgs)
     (Maybe (WithDisabled NotifyActionComplete))
     (Maybe (WithDisabled NotifyActionComplete))
-> Optic'
     A_Lens
     NoIx
     (NotifyArgs r)
     (Maybe (WithDisabled NotifyActionComplete))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (Maybe (WithDisabled NotifyActionComplete))
  (Maybe (WithDisabled NotifyActionComplete))
#complete Maybe (WithDisabled NotifyActionComplete)
-> Maybe (WithDisabled NotifyActionComplete)
-> Maybe NotifyActionComplete
forall (a :: OpticKind).
Maybe (WithDisabled a) -> Maybe (WithDisabled a) -> Maybe a
<|?|> (Maybe (NotifyToml r)
mToml Maybe (NotifyToml r)
-> Optic'
     An_AffineTraversal
     NoIx
     (Maybe (NotifyToml r))
     (WithDisabled NotifyActionComplete)
-> Maybe (WithDisabled NotifyActionComplete)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe (WithDisabled NotifyActionComplete))
  (Maybe (WithDisabled NotifyActionComplete))
-> Optic'
     An_AffineTraversal
     NoIx
     (Maybe (NotifyToml r))
     (WithDisabled NotifyActionComplete)
forall (k :: OpticKind) (m :: OpticKind) (l :: OpticKind)
       (ks :: IxList) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k A_Prism m, JoinKinds A_Prism l k) =>
Optic l ks u v (Maybe a) (Maybe b)
-> Optic m ks (Maybe u) (Maybe v) a b
Utils.surroundJust (Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
#actions Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
-> Optic
     A_Lens
     NoIx
     (NotifyActionsInit 'ConfigPhaseToml)
     (NotifyActionsInit 'ConfigPhaseToml)
     (Maybe (WithDisabled NotifyActionComplete))
     (Maybe (WithDisabled NotifyActionComplete))
-> Optic
     A_Lens
     NoIx
     (NotifyToml r)
     (NotifyToml r)
     (Maybe (WithDisabled NotifyActionComplete))
     (Maybe (WithDisabled NotifyActionComplete))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
  (Maybe (WithDisabled NotifyActionComplete))
  (Maybe (WithDisabled NotifyActionComplete))
#complete))

    mActionStart :: NotifyActionStartSwitch
    mActionStart :: NotifyActionStartSwitch
mActionStart =
      NotifyArgs r
args NotifyArgs r
-> Optic'
     A_Lens NoIx (NotifyArgs r) (Maybe NotifyActionStartSwitch)
-> Maybe NotifyActionStartSwitch
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  (NotifyArgs r)
  (NotifyArgs r)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
#actions Optic
  A_Lens
  NoIx
  (NotifyArgs r)
  (NotifyArgs r)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
-> Optic
     A_Lens
     NoIx
     (NotifyActionsInit 'ConfigPhaseArgs)
     (NotifyActionsInit 'ConfigPhaseArgs)
     (Maybe NotifyActionStartSwitch)
     (Maybe NotifyActionStartSwitch)
-> Optic'
     A_Lens NoIx (NotifyArgs r) (Maybe NotifyActionStartSwitch)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (NotifyActionsInit 'ConfigPhaseArgs)
  (NotifyActionsInit 'ConfigPhaseArgs)
  (Maybe NotifyActionStartSwitch)
  (Maybe NotifyActionStartSwitch)
#start Maybe NotifyActionStartSwitch
-> Maybe NotifyActionStartSwitch -> NotifyActionStartSwitch
forall (a :: OpticKind). Default a => Maybe a -> Maybe a -> a
<.> (Maybe (NotifyToml r)
mToml Maybe (NotifyToml r)
-> Optic'
     An_AffineTraversal
     NoIx
     (Maybe (NotifyToml r))
     NotifyActionStartSwitch
-> Maybe NotifyActionStartSwitch
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (Maybe NotifyActionStartSwitch)
  (Maybe NotifyActionStartSwitch)
-> Optic'
     An_AffineTraversal
     NoIx
     (Maybe (NotifyToml r))
     NotifyActionStartSwitch
forall (k :: OpticKind) (m :: OpticKind) (l :: OpticKind)
       (ks :: IxList) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k A_Prism m, JoinKinds A_Prism l k) =>
Optic l ks u v (Maybe a) (Maybe b)
-> Optic m ks (Maybe u) (Maybe v) a b
Utils.surroundJust (Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
#actions Optic
  A_Lens
  NoIx
  (NotifyToml r)
  (NotifyToml r)
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
-> Optic
     A_Lens
     NoIx
     (NotifyActionsInit 'ConfigPhaseToml)
     (NotifyActionsInit 'ConfigPhaseToml)
     (Maybe NotifyActionStartSwitch)
     (Maybe NotifyActionStartSwitch)
-> Optic
     A_Lens
     NoIx
     (NotifyToml r)
     (NotifyToml r)
     (Maybe NotifyActionStartSwitch)
     (Maybe NotifyActionStartSwitch)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic
  A_Lens
  NoIx
  (NotifyActionsInit 'ConfigPhaseToml)
  (NotifyActionsInit 'ConfigPhaseToml)
  (Maybe NotifyActionStartSwitch)
  (Maybe NotifyActionStartSwitch)
#start))

    mActions :: Maybe NotifyActionsActive
mActions = case (Maybe NotifyActionComplete
mActionComplete, NotifyActionStartSwitch
mActionStart NotifyActionStartSwitch
-> Optic' An_Iso NoIx NotifyActionStartSwitch Bool -> Bool
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' An_Iso NoIx NotifyActionStartSwitch Bool
#unNotifyActionStartSwitch) of
      (Maybe NotifyActionComplete
Nothing, Bool
False) -> Maybe NotifyActionsActive
forall (a :: OpticKind). Maybe a
Nothing
      (Just NotifyActionComplete
actionComplete, Bool
False) -> NotifyActionsActive -> Maybe NotifyActionsActive
forall (a :: OpticKind). a -> Maybe a
Just (NotifyActionsActive -> Maybe NotifyActionsActive)
-> NotifyActionsActive -> Maybe NotifyActionsActive
forall a b. (a -> b) -> a -> b
$ NotifyActionComplete -> NotifyActionsActive
NotifyActionsActiveComplete NotifyActionComplete
actionComplete
      (Maybe NotifyActionComplete
Nothing, Bool
True) -> NotifyActionsActive -> Maybe NotifyActionsActive
forall (a :: OpticKind). a -> Maybe a
Just NotifyActionsActive
NotifyActionsActiveStart
      (Just NotifyActionComplete
actionComplete, Bool
True) -> NotifyActionsActive -> Maybe NotifyActionsActive
forall (a :: OpticKind). a -> Maybe a
Just (NotifyActionsActive -> Maybe NotifyActionsActive)
-> NotifyActionsActive -> Maybe NotifyActionsActive
forall a b. (a -> b) -> a -> b
$ NotifyActionComplete -> NotifyActionsActive
NotifyActionsActiveAll NotifyActionComplete
actionComplete

instance DecodeTOML (NotifyToml r) where
  tomlDecoder :: Decoder (NotifyToml r)
tomlDecoder = do
    Maybe (WithDisabled NotifyActionComplete)
complete <- Decoder (WithDisabled NotifyActionComplete)
-> Text -> Decoder (Maybe (WithDisabled NotifyActionComplete))
forall (a :: OpticKind). Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder (WithDisabled NotifyActionComplete)
forall (a :: OpticKind). DecodeTOML a => Decoder a
tomlDecoder Text
"action-complete"
    Maybe NotifyActionStartSwitch
start <- Decoder NotifyActionStartSwitch
-> Text -> Decoder (Maybe NotifyActionStartSwitch)
forall (a :: OpticKind). Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder NotifyActionStartSwitch
forall (a :: OpticKind). DecodeTOML a => Decoder a
tomlDecoder Text
"action-start"

    let actions :: NotifyActionsInit 'ConfigPhaseToml
actions =
          MkNotifyActionsInit
            { Maybe (WithDisabled NotifyActionComplete)
NotifyActionCompleteF 'ConfigPhaseToml
complete :: NotifyActionCompleteF 'ConfigPhaseToml
complete :: Maybe (WithDisabled NotifyActionComplete)
complete,
              Maybe NotifyActionStartSwitch
SwitchF 'ConfigPhaseToml NotifyActionStartSwitch
start :: SwitchF 'ConfigPhaseToml NotifyActionStartSwitch
start :: Maybe NotifyActionStartSwitch
start
            }

    Maybe NotifySystem
system <- Decoder NotifySystem -> Text -> Decoder (Maybe NotifySystem)
forall (a :: OpticKind). Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith (Decoder Text -> Decoder NotifySystem
forall (m :: OpticKind -> OpticKind).
MonadFail m =>
m Text -> m NotifySystem
parseNotifySystem Decoder Text
forall (a :: OpticKind). DecodeTOML a => Decoder a
tomlDecoder) Text
"system"
    Maybe NotifyTimeout
timeout <- Decoder NotifyTimeout -> Text -> Decoder (Maybe NotifyTimeout)
forall (a :: OpticKind). Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder NotifyTimeout
notifyTimeoutDecoder Text
"timeout"
    pure
      $ MkNotifyP
        { NotifyActionsF 'ConfigPhaseToml
NotifyActionsInit 'ConfigPhaseToml
actions :: NotifyActionsF 'ConfigPhaseToml
actions :: NotifyActionsInit 'ConfigPhaseToml
actions,
          Maybe NotifySystem
NotifySystemF 'ConfigPhaseToml r
system :: NotifySystemF 'ConfigPhaseToml r
system :: Maybe NotifySystem
system,
          Maybe NotifyTimeout
ConfigPhaseF 'ConfigPhaseToml NotifyTimeout
timeout :: ConfigPhaseF 'ConfigPhaseToml NotifyTimeout
timeout :: Maybe NotifyTimeout
timeout
        }

toEnv ::
  ( HasCallStack,
    MonadNotify m,
    MonadThrow m,
    NotifyEnvF m ~ r
  ) =>
  NotifyMerged r ->
  m (NotifyP ConfigPhaseEnv r)
toEnv :: forall (m :: OpticKind -> OpticKind) (r :: OpticKind).
(HasCallStack, MonadNotify m, MonadThrow m, NotifyEnvF m ~ r) =>
NotifyMerged r -> m (NotifyP 'ConfigPhaseEnv r)
toEnv NotifyMerged r
notifyMerged = do
  NotifySystemOs
system <- case NotifySystem -> Either NotifyParseException NotifySystemOs
notifySystemToOs NotifySystem
systemMerged of
    Left NotifyParseException
ex -> NotifyParseException -> m NotifySystemOs
forall (e :: OpticKind) (a :: OpticKind).
(HasCallStack, Exception e) =>
e -> m a
forall (m :: OpticKind -> OpticKind) (e :: OpticKind)
       (a :: OpticKind).
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM NotifyParseException
ex
    Right NotifySystemOs
x -> NotifySystemOs -> m NotifySystemOs
forall (a :: OpticKind). a -> m a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure NotifySystemOs
x
  r
notifyEnv <- NotifySystemOs -> m (NotifyEnvF m)
forall (m :: OpticKind -> OpticKind).
(MonadNotify m, HasCallStack) =>
NotifySystemOs -> m (NotifyEnvF m)
initNotifyEnv NotifySystemOs
system
  pure $ NotifyMerged r
-> NotifySystemF 'ConfigPhaseEnv r -> NotifyP 'ConfigPhaseEnv r
forall (r :: OpticKind).
NotifyMerged r
-> NotifySystemF 'ConfigPhaseEnv r -> NotifyP 'ConfigPhaseEnv r
mkNotify NotifyMerged r
notifyMerged r
NotifySystemF 'ConfigPhaseEnv r
notifyEnv
  where
    systemMerged :: NotifySystem
systemMerged = NotifyMerged r
notifyMerged NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifySystem -> NotifySystem
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifySystem
#system
{-# INLINEABLE toEnv #-}

mkNotify :: NotifyMerged r -> NotifySystemF ConfigPhaseEnv r -> NotifyP ConfigPhaseEnv r
mkNotify :: forall (r :: OpticKind).
NotifyMerged r
-> NotifySystemF 'ConfigPhaseEnv r -> NotifyP 'ConfigPhaseEnv r
mkNotify NotifyMerged r
notifyToml NotifySystemF 'ConfigPhaseEnv r
systemP2 =
  MkNotifyP
    { actions :: NotifyActionsF 'ConfigPhaseEnv
actions = NotifyMerged r
notifyToml NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifyActionsActive
-> NotifyActionsActive
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifyActionsActive
#actions,
      system :: NotifySystemF 'ConfigPhaseEnv r
system = NotifySystemF 'ConfigPhaseEnv r
systemP2,
      timeout :: ConfigPhaseF 'ConfigPhaseEnv NotifyTimeout
timeout = NotifyMerged r
notifyToml NotifyMerged r
-> Optic' A_Lens NoIx (NotifyMerged r) NotifyTimeout
-> NotifyTimeout
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx (NotifyMerged r) NotifyTimeout
#timeout
    }