module Wire.DeleteQueue.InMemory where

import Imports
import Polysemy
import Polysemy.State
import Wire.DeleteQueue
import Wire.InternalEvent

inMemoryDeleteQueueInterpreter :: (Member (State [InternalNotification]) r) => InterpreterFor DeleteQueue r
inMemoryDeleteQueueInterpreter :: forall (r :: EffectRow).
Member (State [InternalNotification]) r =>
InterpreterFor DeleteQueue r
inMemoryDeleteQueueInterpreter = (forall (rInitial :: EffectRow) x.
 DeleteQueue (Sem rInitial) x -> Sem r x)
-> Sem (DeleteQueue : r) a -> Sem r a
forall (e :: (* -> *) -> * -> *) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) x. e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret ((forall (rInitial :: EffectRow) x.
  DeleteQueue (Sem rInitial) x -> Sem r x)
 -> Sem (DeleteQueue : r) a -> Sem r a)
-> (forall (rInitial :: EffectRow) x.
    DeleteQueue (Sem rInitial) x -> Sem r x)
-> Sem (DeleteQueue : r) a
-> Sem r a
forall a b. (a -> b) -> a -> b
$ \case
  EnqueueUserDeletion UserId
uid -> ([InternalNotification] -> [InternalNotification]) -> Sem r ()
forall s (r :: EffectRow).
Member (State s) r =>
(s -> s) -> Sem r ()
modify (\[InternalNotification]
l -> UserId -> InternalNotification
DeleteUser UserId
uid InternalNotification
-> [InternalNotification] -> [InternalNotification]
forall a. a -> [a] -> [a]
: [InternalNotification]
l)
  EnqueueClientDeletion ClientId
cid UserId
uid Maybe ConnId
mConnId -> ([InternalNotification] -> [InternalNotification]) -> Sem r ()
forall s (r :: EffectRow).
Member (State s) r =>
(s -> s) -> Sem r ()
modify (\[InternalNotification]
l -> ClientId -> UserId -> Maybe ConnId -> InternalNotification
DeleteClient ClientId
cid UserId
uid Maybe ConnId
mConnId InternalNotification
-> [InternalNotification] -> [InternalNotification]
forall a. a -> [a] -> [a]
: [InternalNotification]
l)
  EnqueueServiceDeletion ProviderId
pid ServiceId
sid -> ([InternalNotification] -> [InternalNotification]) -> Sem r ()
forall s (r :: EffectRow).
Member (State s) r =>
(s -> s) -> Sem r ()
modify (\[InternalNotification]
l -> ProviderId -> ServiceId -> InternalNotification
DeleteService ProviderId
pid ServiceId
sid InternalNotification
-> [InternalNotification] -> [InternalNotification]
forall a. a -> [a] -> [a]
: [InternalNotification]
l)