{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CodeCommit.Types.Target where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:destinationReference:Target' :: Maybe Text
destinationReference = 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 :: Lens' Target (Maybe Text)
target_destinationReference = 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 :: Lens' Target Text
target_repositoryName = 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 :: Lens' Target Text
target_sourceReference = 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 where
  hashWithSalt :: Int -> Target -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
destinationReference
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
repositoryName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sourceReference

instance Prelude.NFData Target where
  rnf :: Target -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
destinationReference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
repositoryName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sourceReference

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"destinationReference" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
destinationReference,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"repositoryName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
repositoryName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"sourceReference" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sourceReference)
          ]
      )