{-# 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.CodeCommit.Types.Target
-- 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.CodeCommit.Types.Target where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Returns information about a target for a pull request.
--
-- /See:/ 'newTarget' smart constructor.
data Target = Target'
  { -- | The branch of the repository where the pull request changes are merged.
    -- Also known as the destination branch.
    Target -> Maybe Text
destinationReference :: Prelude.Maybe Prelude.Text,
    -- | The name of the repository that contains the pull request.
    Target -> Text
repositoryName :: Prelude.Text,
    -- | The branch of the repository that contains the changes for the pull
    -- request. Also known as the source branch.
    Target -> Text
sourceReference :: Prelude.Text
  }
  deriving (Target -> Target -> Bool
(Target -> Target -> Bool)
-> (Target -> Target -> Bool) -> Eq Target
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Target -> Target -> Bool
$c/= :: Target -> Target -> Bool
== :: Target -> Target -> Bool
$c== :: Target -> Target -> Bool
Prelude.Eq, ReadPrec [Target]
ReadPrec Target
Int -> ReadS Target
ReadS [Target]
(Int -> ReadS Target)
-> ReadS [Target]
-> ReadPrec Target
-> ReadPrec [Target]
-> Read Target
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Target]
$creadListPrec :: ReadPrec [Target]
readPrec :: ReadPrec Target
$creadPrec :: ReadPrec Target
readList :: ReadS [Target]
$creadList :: ReadS [Target]
readsPrec :: Int -> ReadS Target
$creadsPrec :: Int -> ReadS Target
Prelude.Read, Int -> Target -> ShowS
[Target] -> ShowS
Target -> String
(Int -> Target -> ShowS)
-> (Target -> String) -> ([Target] -> ShowS) -> Show Target
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Target] -> ShowS
$cshowList :: [Target] -> ShowS
show :: Target -> String
$cshow :: Target -> String
showsPrec :: Int -> Target -> ShowS
$cshowsPrec :: Int -> Target -> ShowS
Prelude.Show, (forall x. Target -> Rep Target x)
-> (forall x. Rep Target x -> Target) -> Generic Target
forall x. Rep Target x -> Target
forall x. Target -> Rep Target x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Target x -> Target
$cfrom :: forall x. Target -> Rep Target x
Prelude.Generic)

-- |
-- Create a value of 'Target' 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:
--
-- 'destinationReference', 'target_destinationReference' - The branch of the repository where the pull request changes are merged.
-- Also known as the destination branch.
--
-- 'repositoryName', 'target_repositoryName' - The name of the repository that contains the pull request.
--
-- 'sourceReference', 'target_sourceReference' - The branch of the repository that contains the changes for the pull
-- request. Also known as the source branch.
newTarget ::
  -- | 'repositoryName'
  Prelude.Text ->
  -- | 'sourceReference'
  Prelude.Text ->
  Target
newTarget :: Text -> Text -> Target
newTarget Text
pRepositoryName_ Text
pSourceReference_ =
  Target' :: Maybe Text -> Text -> Text -> Target
Target'
    { $sel:destinationReference:Target' :: Maybe Text
destinationReference = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:repositoryName:Target' :: Text
repositoryName = Text
pRepositoryName_,
      $sel:sourceReference:Target' :: Text
sourceReference = Text
pSourceReference_
    }

-- | The branch of the repository where the pull request changes are merged.
-- Also known as the destination branch.
target_destinationReference :: Lens.Lens' Target (Prelude.Maybe Prelude.Text)
target_destinationReference :: (Maybe Text -> f (Maybe Text)) -> Target -> f Target
target_destinationReference = (Target -> Maybe Text)
-> (Target -> Maybe Text -> Target)
-> Lens Target Target (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Target' {Maybe Text
destinationReference :: Maybe Text
$sel:destinationReference:Target' :: Target -> Maybe Text
destinationReference} -> Maybe Text
destinationReference) (\s :: Target
s@Target' {} Maybe Text
a -> Target
s {$sel:destinationReference:Target' :: Maybe Text
destinationReference = Maybe Text
a} :: Target)

-- | The name of the repository that contains the pull request.
target_repositoryName :: Lens.Lens' Target Prelude.Text
target_repositoryName :: (Text -> f Text) -> Target -> f Target
target_repositoryName = (Target -> Text)
-> (Target -> Text -> Target) -> Lens Target Target Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Target' {Text
repositoryName :: Text
$sel:repositoryName:Target' :: Target -> Text
repositoryName} -> Text
repositoryName) (\s :: Target
s@Target' {} Text
a -> Target
s {$sel:repositoryName:Target' :: Text
repositoryName = Text
a} :: Target)

-- | The branch of the repository that contains the changes for the pull
-- request. Also known as the source branch.
target_sourceReference :: Lens.Lens' Target Prelude.Text
target_sourceReference :: (Text -> f Text) -> Target -> f Target
target_sourceReference = (Target -> Text)
-> (Target -> Text -> Target) -> Lens Target Target Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Target' {Text
sourceReference :: Text
$sel:sourceReference:Target' :: Target -> Text
sourceReference} -> Text
sourceReference) (\s :: Target
s@Target' {} Text
a -> Target
s {$sel:sourceReference:Target' :: Text
sourceReference = Text
a} :: Target)

instance Prelude.Hashable Target

instance Prelude.NFData Target

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