{-# LANGUAGE UndecidableInstances #-}

module Shrun.Configuration.Data.MergedConfig
  ( MergedConfig (..),
    defaultMergedConfig,
  )
where

import Shrun.Configuration.Data.Core (CoreConfigMerged)
import Shrun.Configuration.Default (Default (def))
import Shrun.Data.Command (CommandP1)
import Shrun.Prelude

-- | Merged Args + Toml
data MergedConfig = MkMergedConfig
  { -- | Core config.
    MergedConfig -> CoreConfigMerged
coreConfig :: CoreConfigMerged,
    -- | Commands.
    MergedConfig -> NESeq CommandP1
commands :: NESeq CommandP1
  }
  deriving stock (MergedConfig -> MergedConfig -> Bool
(MergedConfig -> MergedConfig -> Bool)
-> (MergedConfig -> MergedConfig -> Bool) -> Eq MergedConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MergedConfig -> MergedConfig -> Bool
== :: MergedConfig -> MergedConfig -> Bool
$c/= :: MergedConfig -> MergedConfig -> Bool
/= :: MergedConfig -> MergedConfig -> Bool
Eq, Int -> MergedConfig -> ShowS
[MergedConfig] -> ShowS
MergedConfig -> String
(Int -> MergedConfig -> ShowS)
-> (MergedConfig -> String)
-> ([MergedConfig] -> ShowS)
-> Show MergedConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MergedConfig -> ShowS
showsPrec :: Int -> MergedConfig -> ShowS
$cshow :: MergedConfig -> String
show :: MergedConfig -> String
$cshowList :: [MergedConfig] -> ShowS
showList :: [MergedConfig] -> ShowS
Show)

instance
  ( k ~ A_Lens,
    a ~ CoreConfigMerged,
    b ~ CoreConfigMerged
  ) =>
  LabelOptic "coreConfig" k MergedConfig MergedConfig a b
  where
  labelOptic :: Optic k NoIx MergedConfig MergedConfig a b
labelOptic =
    LensVL MergedConfig MergedConfig a b
-> Lens MergedConfig MergedConfig a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL MergedConfig MergedConfig a b
 -> Lens MergedConfig MergedConfig a b)
-> LensVL MergedConfig MergedConfig a b
-> Lens MergedConfig MergedConfig a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         (MkMergedConfig CoreConfigMerged
_coreConfig NESeq CommandP1
_commands) ->
          (CoreConfigMerged -> MergedConfig)
-> f CoreConfigMerged -> f MergedConfig
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            (CoreConfigMerged -> NESeq CommandP1 -> MergedConfig
`MkMergedConfig` NESeq CommandP1
_commands)
            (a -> f b
f a
CoreConfigMerged
_coreConfig)
  {-# INLINE labelOptic #-}

instance
  ( k ~ A_Lens,
    a ~ NESeq CommandP1,
    b ~ NESeq CommandP1
  ) =>
  LabelOptic "commands" k MergedConfig MergedConfig a b
  where
  labelOptic :: Optic k NoIx MergedConfig MergedConfig a b
labelOptic =
    LensVL MergedConfig MergedConfig a b
-> Lens MergedConfig MergedConfig a b
forall s t a b. LensVL s t a b -> Lens s t a b
lensVL
      (LensVL MergedConfig MergedConfig a b
 -> Lens MergedConfig MergedConfig a b)
-> LensVL MergedConfig MergedConfig a b
-> Lens MergedConfig MergedConfig a b
forall a b. (a -> b) -> a -> b
$ \a -> f b
f
         (MkMergedConfig CoreConfigMerged
_coreConfig NESeq CommandP1
_commands) ->
          (NESeq CommandP1 -> MergedConfig)
-> f (NESeq CommandP1) -> f MergedConfig
forall a b. (a -> b) -> f a -> f b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap
            (CoreConfigMerged -> NESeq CommandP1 -> MergedConfig
MkMergedConfig CoreConfigMerged
_coreConfig)
            (a -> f b
f a
NESeq CommandP1
_commands)
  {-# INLINE labelOptic #-}

defaultMergedConfig :: NESeq CommandP1 -> MergedConfig
defaultMergedConfig :: NESeq CommandP1 -> MergedConfig
defaultMergedConfig NESeq CommandP1
commands =
  MkMergedConfig
    { coreConfig :: CoreConfigMerged
coreConfig = CoreConfigMerged
forall a. Default a => a
def,
      NESeq CommandP1
commands :: NESeq CommandP1
commands :: NESeq CommandP1
commands
    }