{-# LANGUAGE NoImplicitPrelude     #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors      #-}
{-# LANGUAGE OverloadedRecordDot   #-}

module Stack.Types.DotConfig
  ( DotConfig (..)
  ) where

import           RIO.Process ( HasProcessContext (..) )
import           Stack.Prelude hiding ( Display (..), pkgName, loadPackage )
import           Stack.Types.BuildConfig
                   ( BuildConfig (..), HasBuildConfig (..) )
import           Stack.Types.Config ( HasConfig (..) )
import           Stack.Types.DumpPackage ( DumpPackage (..) )
import           Stack.Types.EnvConfig ( HasSourceMap (..) )
import           Stack.Types.GHCVariant ( HasGHCVariant (..) )
import           Stack.Types.Platform ( HasPlatform (..) )
import           Stack.Types.Runner ( HasRunner (..) )
import           Stack.Types.SourceMap ( SourceMap (..) )

data DotConfig = DotConfig
  { DotConfig -> BuildConfig
buildConfig :: !BuildConfig
  , DotConfig -> SourceMap
sourceMap :: !SourceMap
  , DotConfig -> [DumpPackage]
globalDump :: ![DumpPackage]
  }

instance HasLogFunc DotConfig where
  logFuncL :: Lens' DotConfig LogFunc
logFuncL = (Runner -> f Runner) -> DotConfig -> f DotConfig
forall env. HasRunner env => Lens' env Runner
Lens' DotConfig Runner
runnerL ((Runner -> f Runner) -> DotConfig -> f DotConfig)
-> ((LogFunc -> f LogFunc) -> Runner -> f Runner)
-> (LogFunc -> f LogFunc)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogFunc -> f LogFunc) -> Runner -> f Runner
forall env. HasLogFunc env => Lens' env LogFunc
Lens' Runner LogFunc
logFuncL

instance HasPantryConfig DotConfig where
  pantryConfigL :: Lens' DotConfig PantryConfig
pantryConfigL = (Config -> f Config) -> DotConfig -> f DotConfig
forall env. HasConfig env => Lens' env Config
Lens' DotConfig Config
configL ((Config -> f Config) -> DotConfig -> f DotConfig)
-> ((PantryConfig -> f PantryConfig) -> Config -> f Config)
-> (PantryConfig -> f PantryConfig)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PantryConfig -> f PantryConfig) -> Config -> f Config
forall env. HasPantryConfig env => Lens' env PantryConfig
Lens' Config PantryConfig
pantryConfigL

instance HasTerm DotConfig where
  useColorL :: Lens' DotConfig Bool
useColorL = (Runner -> f Runner) -> DotConfig -> f DotConfig
forall env. HasRunner env => Lens' env Runner
Lens' DotConfig Runner
runnerL ((Runner -> f Runner) -> DotConfig -> f DotConfig)
-> ((Bool -> f Bool) -> Runner -> f Runner)
-> (Bool -> f Bool)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> f Bool) -> Runner -> f Runner
forall env. HasTerm env => Lens' env Bool
Lens' Runner Bool
useColorL
  termWidthL :: Lens' DotConfig Int
termWidthL = (Runner -> f Runner) -> DotConfig -> f DotConfig
forall env. HasRunner env => Lens' env Runner
Lens' DotConfig Runner
runnerL ((Runner -> f Runner) -> DotConfig -> f DotConfig)
-> ((Int -> f Int) -> Runner -> f Runner)
-> (Int -> f Int)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> f Int) -> Runner -> f Runner
forall env. HasTerm env => Lens' env Int
Lens' Runner Int
termWidthL

instance HasStylesUpdate DotConfig where
  stylesUpdateL :: Lens' DotConfig StylesUpdate
stylesUpdateL = (Runner -> f Runner) -> DotConfig -> f DotConfig
forall env. HasRunner env => Lens' env Runner
Lens' DotConfig Runner
runnerL ((Runner -> f Runner) -> DotConfig -> f DotConfig)
-> ((StylesUpdate -> f StylesUpdate) -> Runner -> f Runner)
-> (StylesUpdate -> f StylesUpdate)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (StylesUpdate -> f StylesUpdate) -> Runner -> f Runner
forall env. HasStylesUpdate env => Lens' env StylesUpdate
Lens' Runner StylesUpdate
stylesUpdateL

instance HasGHCVariant DotConfig where
  ghcVariantL :: SimpleGetter DotConfig GHCVariant
ghcVariantL = (Config -> Const r Config) -> DotConfig -> Const r DotConfig
forall env. HasConfig env => Lens' env Config
Lens' DotConfig Config
configL ((Config -> Const r Config) -> DotConfig -> Const r DotConfig)
-> ((GHCVariant -> Const r GHCVariant) -> Config -> Const r Config)
-> (GHCVariant -> Const r GHCVariant)
-> DotConfig
-> Const r DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GHCVariant -> Const r GHCVariant) -> Config -> Const r Config
forall env. HasGHCVariant env => SimpleGetter env GHCVariant
SimpleGetter Config GHCVariant
ghcVariantL
  {-# INLINE ghcVariantL #-}

instance HasPlatform DotConfig where
  platformL :: Lens' DotConfig Platform
platformL = (Config -> f Config) -> DotConfig -> f DotConfig
forall env. HasConfig env => Lens' env Config
Lens' DotConfig Config
configL ((Config -> f Config) -> DotConfig -> f DotConfig)
-> ((Platform -> f Platform) -> Config -> f Config)
-> (Platform -> f Platform)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Platform -> f Platform) -> Config -> f Config
forall env. HasPlatform env => Lens' env Platform
Lens' Config Platform
platformL
  {-# INLINE platformL #-}
  platformVariantL :: Lens' DotConfig PlatformVariant
platformVariantL = (Config -> f Config) -> DotConfig -> f DotConfig
forall env. HasConfig env => Lens' env Config
Lens' DotConfig Config
configL ((Config -> f Config) -> DotConfig -> f DotConfig)
-> ((PlatformVariant -> f PlatformVariant) -> Config -> f Config)
-> (PlatformVariant -> f PlatformVariant)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PlatformVariant -> f PlatformVariant) -> Config -> f Config
forall env. HasPlatform env => Lens' env PlatformVariant
Lens' Config PlatformVariant
platformVariantL
  {-# INLINE platformVariantL #-}

instance HasRunner DotConfig where
  runnerL :: Lens' DotConfig Runner
runnerL = (Config -> f Config) -> DotConfig -> f DotConfig
forall env. HasConfig env => Lens' env Config
Lens' DotConfig Config
configL ((Config -> f Config) -> DotConfig -> f DotConfig)
-> ((Runner -> f Runner) -> Config -> f Config)
-> (Runner -> f Runner)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Runner -> f Runner) -> Config -> f Config
forall env. HasRunner env => Lens' env Runner
Lens' Config Runner
runnerL

instance HasProcessContext DotConfig where
  processContextL :: Lens' DotConfig ProcessContext
processContextL = (Runner -> f Runner) -> DotConfig -> f DotConfig
forall env. HasRunner env => Lens' env Runner
Lens' DotConfig Runner
runnerL ((Runner -> f Runner) -> DotConfig -> f DotConfig)
-> ((ProcessContext -> f ProcessContext) -> Runner -> f Runner)
-> (ProcessContext -> f ProcessContext)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ProcessContext -> f ProcessContext) -> Runner -> f Runner
forall env. HasProcessContext env => Lens' env ProcessContext
Lens' Runner ProcessContext
processContextL

instance HasConfig DotConfig where
  configL :: Lens' DotConfig Config
configL = (BuildConfig -> f BuildConfig) -> DotConfig -> f DotConfig
forall env. HasBuildConfig env => Lens' env BuildConfig
Lens' DotConfig BuildConfig
buildConfigL ((BuildConfig -> f BuildConfig) -> DotConfig -> f DotConfig)
-> ((Config -> f Config) -> BuildConfig -> f BuildConfig)
-> (Config -> f Config)
-> DotConfig
-> f DotConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildConfig -> Config)
-> (BuildConfig -> Config -> BuildConfig)
-> Lens BuildConfig BuildConfig Config Config
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (.config) (\BuildConfig
x Config
y -> BuildConfig
x { config = y })
  {-# INLINE configL #-}

instance HasBuildConfig DotConfig where
  buildConfigL :: Lens' DotConfig BuildConfig
buildConfigL = (DotConfig -> BuildConfig)
-> (DotConfig -> BuildConfig -> DotConfig)
-> Lens' DotConfig BuildConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (.buildConfig) (\DotConfig
x BuildConfig
y -> DotConfig
x { buildConfig = y })

instance HasSourceMap DotConfig where
  sourceMapL :: Lens' DotConfig SourceMap
sourceMapL = (DotConfig -> SourceMap)
-> (DotConfig -> SourceMap -> DotConfig)
-> Lens' DotConfig SourceMap
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (.sourceMap) (\DotConfig
x SourceMap
y -> DotConfig
x { sourceMap = y })