-- |

{-# LANGUAGE TemplateHaskell     #-}

module Gargantext.API.Admin.Types where

import Control.Lens
import Control.Monad.Logger
import Data.ByteString (ByteString)
import GHC.Enum
import GHC.Generics (Generic)
import Gargantext.Prelude
import Servant.Auth.Server (JWTSettings, CookieSettings(..))
import Servant.Client (BaseUrl)


type PortNumber = Int

data SendEmailType = SendEmailViaAws
                   | LogEmailToConsole
                   | WriteEmailToFile
    deriving (Int -> SendEmailType -> ShowS
[SendEmailType] -> ShowS
SendEmailType -> String
(Int -> SendEmailType -> ShowS)
-> (SendEmailType -> String)
-> ([SendEmailType] -> ShowS)
-> Show SendEmailType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SendEmailType] -> ShowS
$cshowList :: [SendEmailType] -> ShowS
show :: SendEmailType -> String
$cshow :: SendEmailType -> String
showsPrec :: Int -> SendEmailType -> ShowS
$cshowsPrec :: Int -> SendEmailType -> ShowS
Show, ReadPrec [SendEmailType]
ReadPrec SendEmailType
Int -> ReadS SendEmailType
ReadS [SendEmailType]
(Int -> ReadS SendEmailType)
-> ReadS [SendEmailType]
-> ReadPrec SendEmailType
-> ReadPrec [SendEmailType]
-> Read SendEmailType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SendEmailType]
$creadListPrec :: ReadPrec [SendEmailType]
readPrec :: ReadPrec SendEmailType
$creadPrec :: ReadPrec SendEmailType
readList :: ReadS [SendEmailType]
$creadList :: ReadS [SendEmailType]
readsPrec :: Int -> ReadS SendEmailType
$creadsPrec :: Int -> ReadS SendEmailType
Read, Int -> SendEmailType
SendEmailType -> Int
SendEmailType -> [SendEmailType]
SendEmailType -> SendEmailType
SendEmailType -> SendEmailType -> [SendEmailType]
SendEmailType -> SendEmailType -> SendEmailType -> [SendEmailType]
(SendEmailType -> SendEmailType)
-> (SendEmailType -> SendEmailType)
-> (Int -> SendEmailType)
-> (SendEmailType -> Int)
-> (SendEmailType -> [SendEmailType])
-> (SendEmailType -> SendEmailType -> [SendEmailType])
-> (SendEmailType -> SendEmailType -> [SendEmailType])
-> (SendEmailType
    -> SendEmailType -> SendEmailType -> [SendEmailType])
-> Enum SendEmailType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: SendEmailType -> SendEmailType -> SendEmailType -> [SendEmailType]
$cenumFromThenTo :: SendEmailType -> SendEmailType -> SendEmailType -> [SendEmailType]
enumFromTo :: SendEmailType -> SendEmailType -> [SendEmailType]
$cenumFromTo :: SendEmailType -> SendEmailType -> [SendEmailType]
enumFromThen :: SendEmailType -> SendEmailType -> [SendEmailType]
$cenumFromThen :: SendEmailType -> SendEmailType -> [SendEmailType]
enumFrom :: SendEmailType -> [SendEmailType]
$cenumFrom :: SendEmailType -> [SendEmailType]
fromEnum :: SendEmailType -> Int
$cfromEnum :: SendEmailType -> Int
toEnum :: Int -> SendEmailType
$ctoEnum :: Int -> SendEmailType
pred :: SendEmailType -> SendEmailType
$cpred :: SendEmailType -> SendEmailType
succ :: SendEmailType -> SendEmailType
$csucc :: SendEmailType -> SendEmailType
Enum, SendEmailType
SendEmailType -> SendEmailType -> Bounded SendEmailType
forall a. a -> a -> Bounded a
maxBound :: SendEmailType
$cmaxBound :: SendEmailType
minBound :: SendEmailType
$cminBound :: SendEmailType
Bounded, (forall x. SendEmailType -> Rep SendEmailType x)
-> (forall x. Rep SendEmailType x -> SendEmailType)
-> Generic SendEmailType
forall x. Rep SendEmailType x -> SendEmailType
forall x. SendEmailType -> Rep SendEmailType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SendEmailType x -> SendEmailType
$cfrom :: forall x. SendEmailType -> Rep SendEmailType x
Generic)

data Settings = Settings
    { Settings -> ByteString
_allowedOrigin   :: !ByteString   -- allowed origin for CORS
    , Settings -> ByteString
_allowedHost     :: !ByteString   -- allowed host for CORS
    , Settings -> Int
_appPort         :: !PortNumber
    , Settings -> LogLevel
_logLevelLimit   :: !LogLevel -- log level from the monad-logger package
--    , _dbServer        :: Text
--    ^ this is not used yet
    , Settings -> JWTSettings
_jwtSettings     :: !JWTSettings
    , Settings -> CookieSettings
_cookieSettings  :: !CookieSettings
    , Settings -> SendEmailType
_sendLoginEmails :: !SendEmailType
    , Settings -> BaseUrl
_scrapydUrl      :: !BaseUrl
    }

makeLenses ''Settings

class HasSettings env where
  settings :: Getter env Settings

instance HasSettings Settings where
  settings :: (Settings -> f Settings) -> Settings -> f Settings
settings = (Settings -> f Settings) -> Settings -> f Settings
forall a. a -> a
identity

data FireWall = FireWall { FireWall -> Bool
unFireWall :: Bool }