{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module ATrade.Driver.Junction.ProgramConfiguration ( ProgramOptions(..), ProgramConfiguration(..) ) where import ATrade.Driver.Junction.Types (StrategyInstanceDescriptor) import ATrade.Logging (Severity (..)) import qualified Data.Text as T import Dhall (FromDhall, autoWith) import Dhall.Core (Expr (..), FieldSelection (..)) import qualified Dhall.Map import Dhall.Marshal.Decode (Decoder (..), typeError) import GHC.Generics (Generic) newtype ProgramOptions = ProgramOptions { configPath :: FilePath } data ProgramConfiguration = ProgramConfiguration { brokerEndpoint :: T.Text, brokerNotificationEndpoint :: T.Text, brokerServerCert :: Maybe FilePath, brokerClientCert :: Maybe FilePath, brokerIdentity :: T.Text, quotesourceEndpoint :: T.Text, quotesourceServerCert :: Maybe FilePath, quotesourceClientCert :: Maybe FilePath, qhpEndpoint :: T.Text, qtisEndpoint :: T.Text, remoteControlEndpoint :: T.Text, redisSocket :: T.Text, robotsConfigsPath :: FilePath, logBasePath :: FilePath, logLevels :: [(T.Text, Severity)], instances :: [StrategyInstanceDescriptor] } deriving (Generic, Show) instance FromDhall Severity where autoWith _ = Decoder {..} where extract expr@(Field _ FieldSelection{ fieldSelectionLabel }) = case fieldSelectionLabel of "Trace" -> pure Trace "Debug" -> pure Debug "Info" -> pure Info "Warning" -> pure Warning "Error" -> pure Error _ -> typeError expected expr extract expr = typeError expected expr expected = pure (Union (Dhall.Map.fromList [ ("Trace", Nothing) , ("Debug", Nothing) , ("Info", Nothing) , ("Warning", Nothing) , ("Error", Nothing) ] ) ) instance FromDhall ProgramConfiguration