{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AppRunner.Types.CodeConfiguration
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AppRunner.Types.CodeConfiguration where

import Amazonka.AppRunner.Types.CodeConfigurationValues
import Amazonka.AppRunner.Types.ConfigurationSource
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the configuration that App Runner uses to build and run an App
-- Runner service from a source code repository.
--
-- /See:/ 'newCodeConfiguration' smart constructor.
data CodeConfiguration = CodeConfiguration'
  { -- | The basic configuration for building and running the App Runner service.
    -- Use it to quickly launch an App Runner service without providing a
    -- @apprunner.yaml@ file in the source code repository (or ignoring the
    -- file if it exists).
    CodeConfiguration -> Maybe CodeConfigurationValues
codeConfigurationValues :: Prelude.Maybe CodeConfigurationValues,
    -- | The source of the App Runner configuration. Values are interpreted as
    -- follows:
    --
    -- -   @REPOSITORY@ – App Runner reads configuration values from the
    --     @apprunner.yaml@ file in the source code repository and ignores
    --     @CodeConfigurationValues@.
    --
    -- -   @API@ – App Runner uses configuration values provided in
    --     @CodeConfigurationValues@ and ignores the @apprunner.yaml@ file in
    --     the source code repository.
    CodeConfiguration -> ConfigurationSource
configurationSource :: ConfigurationSource
  }
  deriving (CodeConfiguration -> CodeConfiguration -> Bool
(CodeConfiguration -> CodeConfiguration -> Bool)
-> (CodeConfiguration -> CodeConfiguration -> Bool)
-> Eq CodeConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CodeConfiguration -> CodeConfiguration -> Bool
$c/= :: CodeConfiguration -> CodeConfiguration -> Bool
== :: CodeConfiguration -> CodeConfiguration -> Bool
$c== :: CodeConfiguration -> CodeConfiguration -> Bool
Prelude.Eq, Int -> CodeConfiguration -> ShowS
[CodeConfiguration] -> ShowS
CodeConfiguration -> String
(Int -> CodeConfiguration -> ShowS)
-> (CodeConfiguration -> String)
-> ([CodeConfiguration] -> ShowS)
-> Show CodeConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CodeConfiguration] -> ShowS
$cshowList :: [CodeConfiguration] -> ShowS
show :: CodeConfiguration -> String
$cshow :: CodeConfiguration -> String
showsPrec :: Int -> CodeConfiguration -> ShowS
$cshowsPrec :: Int -> CodeConfiguration -> ShowS
Prelude.Show, (forall x. CodeConfiguration -> Rep CodeConfiguration x)
-> (forall x. Rep CodeConfiguration x -> CodeConfiguration)
-> Generic CodeConfiguration
forall x. Rep CodeConfiguration x -> CodeConfiguration
forall x. CodeConfiguration -> Rep CodeConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CodeConfiguration x -> CodeConfiguration
$cfrom :: forall x. CodeConfiguration -> Rep CodeConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'CodeConfiguration' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'codeConfigurationValues', 'codeConfiguration_codeConfigurationValues' - The basic configuration for building and running the App Runner service.
-- Use it to quickly launch an App Runner service without providing a
-- @apprunner.yaml@ file in the source code repository (or ignoring the
-- file if it exists).
--
-- 'configurationSource', 'codeConfiguration_configurationSource' - The source of the App Runner configuration. Values are interpreted as
-- follows:
--
-- -   @REPOSITORY@ – App Runner reads configuration values from the
--     @apprunner.yaml@ file in the source code repository and ignores
--     @CodeConfigurationValues@.
--
-- -   @API@ – App Runner uses configuration values provided in
--     @CodeConfigurationValues@ and ignores the @apprunner.yaml@ file in
--     the source code repository.
newCodeConfiguration ::
  -- | 'configurationSource'
  ConfigurationSource ->
  CodeConfiguration
newCodeConfiguration :: ConfigurationSource -> CodeConfiguration
newCodeConfiguration ConfigurationSource
pConfigurationSource_ =
  CodeConfiguration' :: Maybe CodeConfigurationValues
-> ConfigurationSource -> CodeConfiguration
CodeConfiguration'
    { $sel:codeConfigurationValues:CodeConfiguration' :: Maybe CodeConfigurationValues
codeConfigurationValues =
        Maybe CodeConfigurationValues
forall a. Maybe a
Prelude.Nothing,
      $sel:configurationSource:CodeConfiguration' :: ConfigurationSource
configurationSource = ConfigurationSource
pConfigurationSource_
    }

-- | The basic configuration for building and running the App Runner service.
-- Use it to quickly launch an App Runner service without providing a
-- @apprunner.yaml@ file in the source code repository (or ignoring the
-- file if it exists).
codeConfiguration_codeConfigurationValues :: Lens.Lens' CodeConfiguration (Prelude.Maybe CodeConfigurationValues)
codeConfiguration_codeConfigurationValues :: (Maybe CodeConfigurationValues
 -> f (Maybe CodeConfigurationValues))
-> CodeConfiguration -> f CodeConfiguration
codeConfiguration_codeConfigurationValues = (CodeConfiguration -> Maybe CodeConfigurationValues)
-> (CodeConfiguration
    -> Maybe CodeConfigurationValues -> CodeConfiguration)
-> Lens
     CodeConfiguration
     CodeConfiguration
     (Maybe CodeConfigurationValues)
     (Maybe CodeConfigurationValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeConfiguration' {Maybe CodeConfigurationValues
codeConfigurationValues :: Maybe CodeConfigurationValues
$sel:codeConfigurationValues:CodeConfiguration' :: CodeConfiguration -> Maybe CodeConfigurationValues
codeConfigurationValues} -> Maybe CodeConfigurationValues
codeConfigurationValues) (\s :: CodeConfiguration
s@CodeConfiguration' {} Maybe CodeConfigurationValues
a -> CodeConfiguration
s {$sel:codeConfigurationValues:CodeConfiguration' :: Maybe CodeConfigurationValues
codeConfigurationValues = Maybe CodeConfigurationValues
a} :: CodeConfiguration)

-- | The source of the App Runner configuration. Values are interpreted as
-- follows:
--
-- -   @REPOSITORY@ – App Runner reads configuration values from the
--     @apprunner.yaml@ file in the source code repository and ignores
--     @CodeConfigurationValues@.
--
-- -   @API@ – App Runner uses configuration values provided in
--     @CodeConfigurationValues@ and ignores the @apprunner.yaml@ file in
--     the source code repository.
codeConfiguration_configurationSource :: Lens.Lens' CodeConfiguration ConfigurationSource
codeConfiguration_configurationSource :: (ConfigurationSource -> f ConfigurationSource)
-> CodeConfiguration -> f CodeConfiguration
codeConfiguration_configurationSource = (CodeConfiguration -> ConfigurationSource)
-> (CodeConfiguration -> ConfigurationSource -> CodeConfiguration)
-> Lens
     CodeConfiguration
     CodeConfiguration
     ConfigurationSource
     ConfigurationSource
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CodeConfiguration' {ConfigurationSource
configurationSource :: ConfigurationSource
$sel:configurationSource:CodeConfiguration' :: CodeConfiguration -> ConfigurationSource
configurationSource} -> ConfigurationSource
configurationSource) (\s :: CodeConfiguration
s@CodeConfiguration' {} ConfigurationSource
a -> CodeConfiguration
s {$sel:configurationSource:CodeConfiguration' :: ConfigurationSource
configurationSource = ConfigurationSource
a} :: CodeConfiguration)

instance Core.FromJSON CodeConfiguration where
  parseJSON :: Value -> Parser CodeConfiguration
parseJSON =
    String
-> (Object -> Parser CodeConfiguration)
-> Value
-> Parser CodeConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CodeConfiguration"
      ( \Object
x ->
          Maybe CodeConfigurationValues
-> ConfigurationSource -> CodeConfiguration
CodeConfiguration'
            (Maybe CodeConfigurationValues
 -> ConfigurationSource -> CodeConfiguration)
-> Parser (Maybe CodeConfigurationValues)
-> Parser (ConfigurationSource -> CodeConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe CodeConfigurationValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CodeConfigurationValues")
            Parser (ConfigurationSource -> CodeConfiguration)
-> Parser ConfigurationSource -> Parser CodeConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ConfigurationSource
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConfigurationSource")
      )

instance Prelude.Hashable CodeConfiguration

instance Prelude.NFData CodeConfiguration

instance Core.ToJSON CodeConfiguration where
  toJSON :: CodeConfiguration -> Value
toJSON CodeConfiguration' {Maybe CodeConfigurationValues
ConfigurationSource
configurationSource :: ConfigurationSource
codeConfigurationValues :: Maybe CodeConfigurationValues
$sel:configurationSource:CodeConfiguration' :: CodeConfiguration -> ConfigurationSource
$sel:codeConfigurationValues:CodeConfiguration' :: CodeConfiguration -> Maybe CodeConfigurationValues
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CodeConfigurationValues" Text -> CodeConfigurationValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CodeConfigurationValues -> Pair)
-> Maybe CodeConfigurationValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CodeConfigurationValues
codeConfigurationValues,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ConfigurationSource" Text -> ConfigurationSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConfigurationSource
configurationSource)
          ]
      )