module Evoke.Type.Config
  ( Config (..),
    fromFlags,
  )
where

import qualified Data.List as List
import qualified Evoke.Type.Flag as Flag

data Config = Config
  { Config -> Bool
help :: Bool,
    Config -> Bool
verbose :: Bool,
    Config -> Bool
version :: Bool
  }
  deriving (Config -> Config -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Config -> Config -> Bool
$c/= :: Config -> Config -> Bool
== :: Config -> Config -> Bool
$c== :: Config -> Config -> Bool
Eq, Int -> Config -> ShowS
[Config] -> ShowS
Config -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Config] -> ShowS
$cshowList :: [Config] -> ShowS
show :: Config -> String
$cshow :: Config -> String
showsPrec :: Int -> Config -> ShowS
$cshowsPrec :: Int -> Config -> ShowS
Show)

initial :: Config
initial :: Config
initial = Config {help :: Bool
help = Bool
False, verbose :: Bool
verbose = Bool
False, version :: Bool
version = Bool
False}

fromFlags :: Foldable t => t Flag.Flag -> Config
fromFlags :: forall (t :: * -> *). Foldable t => t Flag -> Config
fromFlags = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' Config -> Flag -> Config
applyFlag Config
initial

applyFlag :: Config -> Flag.Flag -> Config
applyFlag :: Config -> Flag -> Config
applyFlag Config
config Flag
flag = case Flag
flag of
  Flag
Flag.Help -> Config
config {help :: Bool
help = Bool
True}
  Flag
Flag.Verbose -> Config
config {verbose :: Bool
verbose = Bool
True}
  Flag
Flag.Version -> Config
config {version :: Bool
version = Bool
True}