{-# 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.CodeStar.Types.Code
-- 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.CodeStar.Types.Code where

import Amazonka.CodeStar.Types.CodeDestination
import Amazonka.CodeStar.Types.CodeSource
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Location and destination information about the source code files
-- provided with the project request. The source code is uploaded to the
-- new project source repository after project creation.
--
-- /See:/ 'newCode' smart constructor.
data Code = Code'
  { -- | The location where the source code files provided with the project
    -- request are stored. AWS CodeStar retrieves the files during project
    -- creation.
    Code -> CodeSource
source :: CodeSource,
    -- | The repository to be created in AWS CodeStar. Valid values are AWS
    -- CodeCommit or GitHub. After AWS CodeStar provisions the new repository,
    -- the source code files provided with the project request are placed in
    -- the repository.
    Code -> CodeDestination
destination :: CodeDestination
  }
  deriving (Code -> Code -> Bool
(Code -> Code -> Bool) -> (Code -> Code -> Bool) -> Eq Code
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Code -> Code -> Bool
$c/= :: Code -> Code -> Bool
== :: Code -> Code -> Bool
$c== :: Code -> Code -> Bool
Prelude.Eq, Int -> Code -> ShowS
[Code] -> ShowS
Code -> String
(Int -> Code -> ShowS)
-> (Code -> String) -> ([Code] -> ShowS) -> Show Code
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Code] -> ShowS
$cshowList :: [Code] -> ShowS
show :: Code -> String
$cshow :: Code -> String
showsPrec :: Int -> Code -> ShowS
$cshowsPrec :: Int -> Code -> ShowS
Prelude.Show, (forall x. Code -> Rep Code x)
-> (forall x. Rep Code x -> Code) -> Generic Code
forall x. Rep Code x -> Code
forall x. Code -> Rep Code x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Code x -> Code
$cfrom :: forall x. Code -> Rep Code x
Prelude.Generic)

-- |
-- Create a value of 'Code' 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:
--
-- 'source', 'code_source' - The location where the source code files provided with the project
-- request are stored. AWS CodeStar retrieves the files during project
-- creation.
--
-- 'destination', 'code_destination' - The repository to be created in AWS CodeStar. Valid values are AWS
-- CodeCommit or GitHub. After AWS CodeStar provisions the new repository,
-- the source code files provided with the project request are placed in
-- the repository.
newCode ::
  -- | 'source'
  CodeSource ->
  -- | 'destination'
  CodeDestination ->
  Code
newCode :: CodeSource -> CodeDestination -> Code
newCode CodeSource
pSource_ CodeDestination
pDestination_ =
  Code' :: CodeSource -> CodeDestination -> Code
Code'
    { $sel:source:Code' :: CodeSource
source = CodeSource
pSource_,
      $sel:destination:Code' :: CodeDestination
destination = CodeDestination
pDestination_
    }

-- | The location where the source code files provided with the project
-- request are stored. AWS CodeStar retrieves the files during project
-- creation.
code_source :: Lens.Lens' Code CodeSource
code_source :: (CodeSource -> f CodeSource) -> Code -> f Code
code_source = (Code -> CodeSource)
-> (Code -> CodeSource -> Code)
-> Lens Code Code CodeSource CodeSource
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Code' {CodeSource
source :: CodeSource
$sel:source:Code' :: Code -> CodeSource
source} -> CodeSource
source) (\s :: Code
s@Code' {} CodeSource
a -> Code
s {$sel:source:Code' :: CodeSource
source = CodeSource
a} :: Code)

-- | The repository to be created in AWS CodeStar. Valid values are AWS
-- CodeCommit or GitHub. After AWS CodeStar provisions the new repository,
-- the source code files provided with the project request are placed in
-- the repository.
code_destination :: Lens.Lens' Code CodeDestination
code_destination :: (CodeDestination -> f CodeDestination) -> Code -> f Code
code_destination = (Code -> CodeDestination)
-> (Code -> CodeDestination -> Code)
-> Lens Code Code CodeDestination CodeDestination
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Code' {CodeDestination
destination :: CodeDestination
$sel:destination:Code' :: Code -> CodeDestination
destination} -> CodeDestination
destination) (\s :: Code
s@Code' {} CodeDestination
a -> Code
s {$sel:destination:Code' :: CodeDestination
destination = CodeDestination
a} :: Code)

instance Prelude.Hashable Code

instance Prelude.NFData Code

instance Core.ToJSON Code where
  toJSON :: Code -> Value
toJSON Code' {CodeDestination
CodeSource
destination :: CodeDestination
source :: CodeSource
$sel:destination:Code' :: Code -> CodeDestination
$sel:source:Code' :: Code -> CodeSource
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"source" Text -> CodeSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CodeSource
source),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"destination" Text -> CodeDestination -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CodeDestination
destination)
          ]
      )