{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wno-ambiguous-fields #-}

module Wire.SessionStore where

import Cassandra
import Data.Id
import Data.Time.Clock
import Imports
import Polysemy
import Test.QuickCheck
import Wire.API.User.Auth

newtype TTL = TTL {TTL -> Int32
ttlSeconds :: Int32}
  deriving (Int -> TTL -> ShowS
[TTL] -> ShowS
TTL -> String
(Int -> TTL -> ShowS)
-> (TTL -> String) -> ([TTL] -> ShowS) -> Show TTL
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TTL -> ShowS
showsPrec :: Int -> TTL -> ShowS
$cshow :: TTL -> String
show :: TTL -> String
$cshowList :: [TTL] -> ShowS
showList :: [TTL] -> ShowS
Show, TTL -> TTL -> Bool
(TTL -> TTL -> Bool) -> (TTL -> TTL -> Bool) -> Eq TTL
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TTL -> TTL -> Bool
== :: TTL -> TTL -> Bool
$c/= :: TTL -> TTL -> Bool
/= :: TTL -> TTL -> Bool
Eq)
  deriving newtype (Tagged TTL ColumnType
Tagged TTL ColumnType
-> (TTL -> Value) -> (Value -> Either String TTL) -> Cql TTL
Value -> Either String TTL
TTL -> Value
forall a.
Tagged a ColumnType
-> (a -> Value) -> (Value -> Either String a) -> Cql a
$cctype :: Tagged TTL ColumnType
ctype :: Tagged TTL ColumnType
$ctoCql :: TTL -> Value
toCql :: TTL -> Value
$cfromCql :: Value -> Either String TTL
fromCql :: Value -> Either String TTL
Cql, Gen TTL
Gen TTL -> (TTL -> [TTL]) -> Arbitrary TTL
TTL -> [TTL]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen TTL
arbitrary :: Gen TTL
$cshrink :: TTL -> [TTL]
shrink :: TTL -> [TTL]
Arbitrary)

data SessionStore m a where
  InsertCookie :: UserId -> Cookie () -> Maybe TTL -> SessionStore m ()
  LookupCookie :: UserId -> UTCTime -> CookieId -> SessionStore m (Maybe (Cookie ()))
  ListCookies :: UserId -> SessionStore m [Cookie ()]
  DeleteAllCookies :: UserId -> SessionStore m ()
  DeleteCookies :: UserId -> [Cookie ()] -> SessionStore m ()

makeSem ''SessionStore