module Gamgee.Effects
  ( module Gamgee.Effects.Crypto
  , module Gamgee.Effects.CryptoRandom
  , module Gamgee.Effects.JSONStore
  , module Gamgee.Effects.ByteStore
  , module Gamgee.Effects.SecretInput
  , module Gamgee.Effects.TOTP
  , module Gamgee.Effects.Error

  , runStateJSON
  ) where

import           Gamgee.Effects.ByteStore
import           Gamgee.Effects.Crypto
import           Gamgee.Effects.CryptoRandom
import           Gamgee.Effects.Error
import           Gamgee.Effects.JSONStore
import           Gamgee.Effects.SecretInput
import           Gamgee.Effects.TOTP
import           Polysemy                    (Sem)
import qualified Polysemy                    as P
import qualified Polysemy.State              as P
import           Relude


----------------------------------------------------------------------------------------------------
-- Reinterpret State backed by a JSON store
----------------------------------------------------------------------------------------------------

runStateJSON :: Sem (P.State o : r) a -> Sem (JSONStore o : r) a
runStateJSON :: Sem (State o : r) a -> Sem (JSONStore o : r) a
runStateJSON = (forall (rInitial :: EffectRow) x.
 State o (Sem rInitial) x -> Sem (JSONStore o : r) x)
-> Sem (State o : r) a -> Sem (JSONStore o : r) a
forall (e1 :: (* -> *) -> * -> *) (e2 :: (* -> *) -> * -> *)
       (r :: EffectRow) a.
FirstOrder e1 "reinterpret" =>
(forall (rInitial :: EffectRow) x.
 e1 (Sem rInitial) x -> Sem (e2 : r) x)
-> Sem (e1 : r) a -> Sem (e2 : r) a
P.reinterpret ((forall (rInitial :: EffectRow) x.
  State o (Sem rInitial) x -> Sem (JSONStore o : r) x)
 -> Sem (State o : r) a -> Sem (JSONStore o : r) a)
-> (forall (rInitial :: EffectRow) x.
    State o (Sem rInitial) x -> Sem (JSONStore o : r) x)
-> Sem (State o : r) a
-> Sem (JSONStore o : r) a
forall a b. (a -> b) -> a -> b
$ \case
  State o (Sem rInitial) x
P.Get   -> Sem (JSONStore o : r) x
forall o (r :: EffectRow).
MemberWithError (JSONStore o) r =>
Sem r o
jsonDecode
  P.Put s -> o -> Sem (JSONStore o : r) ()
forall o (r :: EffectRow).
MemberWithError (JSONStore o) r =>
o -> Sem r ()
jsonEncode o
s