{-# 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.CodeGuruReviewer.Types.CommitDiffSourceCodeType
-- 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.CodeGuruReviewer.Types.CommitDiffSourceCodeType where

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

-- | A type of
-- <https://docs.aws.amazon.com/codeguru/latest/reviewer-api/API_SourceCodeType SourceCodeType>
-- that specifies the commit diff for a pull request on an associated
-- repository. The @SourceCommit@ and @DestinationCommit@ fields are
-- required to do a pull request code review.
--
-- /See:/ 'newCommitDiffSourceCodeType' smart constructor.
data CommitDiffSourceCodeType = CommitDiffSourceCodeType'
  { -- | The SHA of the source commit used to generate a commit diff. This field
    -- is required for a pull request code review.
    CommitDiffSourceCodeType -> Maybe Text
sourceCommit :: Prelude.Maybe Prelude.Text,
    -- | The SHA of the merge base of a commit.
    CommitDiffSourceCodeType -> Maybe Text
mergeBaseCommit :: Prelude.Maybe Prelude.Text,
    -- | The SHA of the destination commit used to generate a commit diff. This
    -- field is required for a pull request code review.
    CommitDiffSourceCodeType -> Maybe Text
destinationCommit :: Prelude.Maybe Prelude.Text
  }
  deriving (CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool
(CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool)
-> (CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool)
-> Eq CommitDiffSourceCodeType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool
$c/= :: CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool
== :: CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool
$c== :: CommitDiffSourceCodeType -> CommitDiffSourceCodeType -> Bool
Prelude.Eq, ReadPrec [CommitDiffSourceCodeType]
ReadPrec CommitDiffSourceCodeType
Int -> ReadS CommitDiffSourceCodeType
ReadS [CommitDiffSourceCodeType]
(Int -> ReadS CommitDiffSourceCodeType)
-> ReadS [CommitDiffSourceCodeType]
-> ReadPrec CommitDiffSourceCodeType
-> ReadPrec [CommitDiffSourceCodeType]
-> Read CommitDiffSourceCodeType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CommitDiffSourceCodeType]
$creadListPrec :: ReadPrec [CommitDiffSourceCodeType]
readPrec :: ReadPrec CommitDiffSourceCodeType
$creadPrec :: ReadPrec CommitDiffSourceCodeType
readList :: ReadS [CommitDiffSourceCodeType]
$creadList :: ReadS [CommitDiffSourceCodeType]
readsPrec :: Int -> ReadS CommitDiffSourceCodeType
$creadsPrec :: Int -> ReadS CommitDiffSourceCodeType
Prelude.Read, Int -> CommitDiffSourceCodeType -> ShowS
[CommitDiffSourceCodeType] -> ShowS
CommitDiffSourceCodeType -> String
(Int -> CommitDiffSourceCodeType -> ShowS)
-> (CommitDiffSourceCodeType -> String)
-> ([CommitDiffSourceCodeType] -> ShowS)
-> Show CommitDiffSourceCodeType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommitDiffSourceCodeType] -> ShowS
$cshowList :: [CommitDiffSourceCodeType] -> ShowS
show :: CommitDiffSourceCodeType -> String
$cshow :: CommitDiffSourceCodeType -> String
showsPrec :: Int -> CommitDiffSourceCodeType -> ShowS
$cshowsPrec :: Int -> CommitDiffSourceCodeType -> ShowS
Prelude.Show, (forall x.
 CommitDiffSourceCodeType -> Rep CommitDiffSourceCodeType x)
-> (forall x.
    Rep CommitDiffSourceCodeType x -> CommitDiffSourceCodeType)
-> Generic CommitDiffSourceCodeType
forall x.
Rep CommitDiffSourceCodeType x -> CommitDiffSourceCodeType
forall x.
CommitDiffSourceCodeType -> Rep CommitDiffSourceCodeType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CommitDiffSourceCodeType x -> CommitDiffSourceCodeType
$cfrom :: forall x.
CommitDiffSourceCodeType -> Rep CommitDiffSourceCodeType x
Prelude.Generic)

-- |
-- Create a value of 'CommitDiffSourceCodeType' 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:
--
-- 'sourceCommit', 'commitDiffSourceCodeType_sourceCommit' - The SHA of the source commit used to generate a commit diff. This field
-- is required for a pull request code review.
--
-- 'mergeBaseCommit', 'commitDiffSourceCodeType_mergeBaseCommit' - The SHA of the merge base of a commit.
--
-- 'destinationCommit', 'commitDiffSourceCodeType_destinationCommit' - The SHA of the destination commit used to generate a commit diff. This
-- field is required for a pull request code review.
newCommitDiffSourceCodeType ::
  CommitDiffSourceCodeType
newCommitDiffSourceCodeType :: CommitDiffSourceCodeType
newCommitDiffSourceCodeType =
  CommitDiffSourceCodeType' :: Maybe Text -> Maybe Text -> Maybe Text -> CommitDiffSourceCodeType
CommitDiffSourceCodeType'
    { $sel:sourceCommit:CommitDiffSourceCodeType' :: Maybe Text
sourceCommit =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:mergeBaseCommit:CommitDiffSourceCodeType' :: Maybe Text
mergeBaseCommit = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:destinationCommit:CommitDiffSourceCodeType' :: Maybe Text
destinationCommit = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The SHA of the source commit used to generate a commit diff. This field
-- is required for a pull request code review.
commitDiffSourceCodeType_sourceCommit :: Lens.Lens' CommitDiffSourceCodeType (Prelude.Maybe Prelude.Text)
commitDiffSourceCodeType_sourceCommit :: (Maybe Text -> f (Maybe Text))
-> CommitDiffSourceCodeType -> f CommitDiffSourceCodeType
commitDiffSourceCodeType_sourceCommit = (CommitDiffSourceCodeType -> Maybe Text)
-> (CommitDiffSourceCodeType
    -> Maybe Text -> CommitDiffSourceCodeType)
-> Lens
     CommitDiffSourceCodeType
     CommitDiffSourceCodeType
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitDiffSourceCodeType' {Maybe Text
sourceCommit :: Maybe Text
$sel:sourceCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
sourceCommit} -> Maybe Text
sourceCommit) (\s :: CommitDiffSourceCodeType
s@CommitDiffSourceCodeType' {} Maybe Text
a -> CommitDiffSourceCodeType
s {$sel:sourceCommit:CommitDiffSourceCodeType' :: Maybe Text
sourceCommit = Maybe Text
a} :: CommitDiffSourceCodeType)

-- | The SHA of the merge base of a commit.
commitDiffSourceCodeType_mergeBaseCommit :: Lens.Lens' CommitDiffSourceCodeType (Prelude.Maybe Prelude.Text)
commitDiffSourceCodeType_mergeBaseCommit :: (Maybe Text -> f (Maybe Text))
-> CommitDiffSourceCodeType -> f CommitDiffSourceCodeType
commitDiffSourceCodeType_mergeBaseCommit = (CommitDiffSourceCodeType -> Maybe Text)
-> (CommitDiffSourceCodeType
    -> Maybe Text -> CommitDiffSourceCodeType)
-> Lens
     CommitDiffSourceCodeType
     CommitDiffSourceCodeType
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitDiffSourceCodeType' {Maybe Text
mergeBaseCommit :: Maybe Text
$sel:mergeBaseCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
mergeBaseCommit} -> Maybe Text
mergeBaseCommit) (\s :: CommitDiffSourceCodeType
s@CommitDiffSourceCodeType' {} Maybe Text
a -> CommitDiffSourceCodeType
s {$sel:mergeBaseCommit:CommitDiffSourceCodeType' :: Maybe Text
mergeBaseCommit = Maybe Text
a} :: CommitDiffSourceCodeType)

-- | The SHA of the destination commit used to generate a commit diff. This
-- field is required for a pull request code review.
commitDiffSourceCodeType_destinationCommit :: Lens.Lens' CommitDiffSourceCodeType (Prelude.Maybe Prelude.Text)
commitDiffSourceCodeType_destinationCommit :: (Maybe Text -> f (Maybe Text))
-> CommitDiffSourceCodeType -> f CommitDiffSourceCodeType
commitDiffSourceCodeType_destinationCommit = (CommitDiffSourceCodeType -> Maybe Text)
-> (CommitDiffSourceCodeType
    -> Maybe Text -> CommitDiffSourceCodeType)
-> Lens
     CommitDiffSourceCodeType
     CommitDiffSourceCodeType
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CommitDiffSourceCodeType' {Maybe Text
destinationCommit :: Maybe Text
$sel:destinationCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
destinationCommit} -> Maybe Text
destinationCommit) (\s :: CommitDiffSourceCodeType
s@CommitDiffSourceCodeType' {} Maybe Text
a -> CommitDiffSourceCodeType
s {$sel:destinationCommit:CommitDiffSourceCodeType' :: Maybe Text
destinationCommit = Maybe Text
a} :: CommitDiffSourceCodeType)

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

instance Prelude.Hashable CommitDiffSourceCodeType

instance Prelude.NFData CommitDiffSourceCodeType

instance Core.ToJSON CommitDiffSourceCodeType where
  toJSON :: CommitDiffSourceCodeType -> Value
toJSON CommitDiffSourceCodeType' {Maybe Text
destinationCommit :: Maybe Text
mergeBaseCommit :: Maybe Text
sourceCommit :: Maybe Text
$sel:destinationCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
$sel:mergeBaseCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
$sel:sourceCommit:CommitDiffSourceCodeType' :: CommitDiffSourceCodeType -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SourceCommit" 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
sourceCommit,
            (Text
"MergeBaseCommit" 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
mergeBaseCommit,
            (Text
"DestinationCommit" 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
destinationCommit
          ]
      )