{-# 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.RequestMetadata
-- 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.RequestMetadata where

import Amazonka.CodeGuruReviewer.Types.EventInfo
import Amazonka.CodeGuruReviewer.Types.VendorName
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Metadata that is associated with a code review. This applies to both
-- pull request and repository analysis code reviews.
--
-- /See:/ 'newRequestMetadata' smart constructor.
data RequestMetadata = RequestMetadata'
  { -- | The ID of the request. This is required for a pull request code review.
    RequestMetadata -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | Information about the event associated with a code review.
    RequestMetadata -> Maybe EventInfo
eventInfo :: Prelude.Maybe EventInfo,
    -- | The name of the repository vendor used to upload code to an S3 bucket
    -- for a CI\/CD code review. For example, if code and artifacts are
    -- uploaded to an S3 bucket for a CI\/CD code review by GitHub scripts from
    -- a GitHub repository, then the repository association\'s @ProviderType@
    -- is @S3Bucket@ and the CI\/CD repository vendor name is GitHub. For more
    -- information, see the definition for @ProviderType@ in
    -- <https://docs.aws.amazon.com/codeguru/latest/reviewer-api/API_RepositoryAssociation.html RepositoryAssociation>.
    RequestMetadata -> Maybe VendorName
vendorName :: Prelude.Maybe VendorName,
    -- | An identifier, such as a name or account ID, that is associated with the
    -- requester. The @Requester@ is used to capture the @author\/actor@ name
    -- of the event request.
    RequestMetadata -> Maybe Text
requester :: Prelude.Maybe Prelude.Text
  }
  deriving (RequestMetadata -> RequestMetadata -> Bool
(RequestMetadata -> RequestMetadata -> Bool)
-> (RequestMetadata -> RequestMetadata -> Bool)
-> Eq RequestMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RequestMetadata -> RequestMetadata -> Bool
$c/= :: RequestMetadata -> RequestMetadata -> Bool
== :: RequestMetadata -> RequestMetadata -> Bool
$c== :: RequestMetadata -> RequestMetadata -> Bool
Prelude.Eq, ReadPrec [RequestMetadata]
ReadPrec RequestMetadata
Int -> ReadS RequestMetadata
ReadS [RequestMetadata]
(Int -> ReadS RequestMetadata)
-> ReadS [RequestMetadata]
-> ReadPrec RequestMetadata
-> ReadPrec [RequestMetadata]
-> Read RequestMetadata
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RequestMetadata]
$creadListPrec :: ReadPrec [RequestMetadata]
readPrec :: ReadPrec RequestMetadata
$creadPrec :: ReadPrec RequestMetadata
readList :: ReadS [RequestMetadata]
$creadList :: ReadS [RequestMetadata]
readsPrec :: Int -> ReadS RequestMetadata
$creadsPrec :: Int -> ReadS RequestMetadata
Prelude.Read, Int -> RequestMetadata -> ShowS
[RequestMetadata] -> ShowS
RequestMetadata -> String
(Int -> RequestMetadata -> ShowS)
-> (RequestMetadata -> String)
-> ([RequestMetadata] -> ShowS)
-> Show RequestMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RequestMetadata] -> ShowS
$cshowList :: [RequestMetadata] -> ShowS
show :: RequestMetadata -> String
$cshow :: RequestMetadata -> String
showsPrec :: Int -> RequestMetadata -> ShowS
$cshowsPrec :: Int -> RequestMetadata -> ShowS
Prelude.Show, (forall x. RequestMetadata -> Rep RequestMetadata x)
-> (forall x. Rep RequestMetadata x -> RequestMetadata)
-> Generic RequestMetadata
forall x. Rep RequestMetadata x -> RequestMetadata
forall x. RequestMetadata -> Rep RequestMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RequestMetadata x -> RequestMetadata
$cfrom :: forall x. RequestMetadata -> Rep RequestMetadata x
Prelude.Generic)

-- |
-- Create a value of 'RequestMetadata' 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:
--
-- 'requestId', 'requestMetadata_requestId' - The ID of the request. This is required for a pull request code review.
--
-- 'eventInfo', 'requestMetadata_eventInfo' - Information about the event associated with a code review.
--
-- 'vendorName', 'requestMetadata_vendorName' - The name of the repository vendor used to upload code to an S3 bucket
-- for a CI\/CD code review. For example, if code and artifacts are
-- uploaded to an S3 bucket for a CI\/CD code review by GitHub scripts from
-- a GitHub repository, then the repository association\'s @ProviderType@
-- is @S3Bucket@ and the CI\/CD repository vendor name is GitHub. For more
-- information, see the definition for @ProviderType@ in
-- <https://docs.aws.amazon.com/codeguru/latest/reviewer-api/API_RepositoryAssociation.html RepositoryAssociation>.
--
-- 'requester', 'requestMetadata_requester' - An identifier, such as a name or account ID, that is associated with the
-- requester. The @Requester@ is used to capture the @author\/actor@ name
-- of the event request.
newRequestMetadata ::
  RequestMetadata
newRequestMetadata :: RequestMetadata
newRequestMetadata =
  RequestMetadata' :: Maybe Text
-> Maybe EventInfo
-> Maybe VendorName
-> Maybe Text
-> RequestMetadata
RequestMetadata'
    { $sel:requestId:RequestMetadata' :: Maybe Text
requestId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventInfo:RequestMetadata' :: Maybe EventInfo
eventInfo = Maybe EventInfo
forall a. Maybe a
Prelude.Nothing,
      $sel:vendorName:RequestMetadata' :: Maybe VendorName
vendorName = Maybe VendorName
forall a. Maybe a
Prelude.Nothing,
      $sel:requester:RequestMetadata' :: Maybe Text
requester = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the request. This is required for a pull request code review.
requestMetadata_requestId :: Lens.Lens' RequestMetadata (Prelude.Maybe Prelude.Text)
requestMetadata_requestId :: (Maybe Text -> f (Maybe Text))
-> RequestMetadata -> f RequestMetadata
requestMetadata_requestId = (RequestMetadata -> Maybe Text)
-> (RequestMetadata -> Maybe Text -> RequestMetadata)
-> Lens RequestMetadata RequestMetadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestMetadata' {Maybe Text
requestId :: Maybe Text
$sel:requestId:RequestMetadata' :: RequestMetadata -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: RequestMetadata
s@RequestMetadata' {} Maybe Text
a -> RequestMetadata
s {$sel:requestId:RequestMetadata' :: Maybe Text
requestId = Maybe Text
a} :: RequestMetadata)

-- | Information about the event associated with a code review.
requestMetadata_eventInfo :: Lens.Lens' RequestMetadata (Prelude.Maybe EventInfo)
requestMetadata_eventInfo :: (Maybe EventInfo -> f (Maybe EventInfo))
-> RequestMetadata -> f RequestMetadata
requestMetadata_eventInfo = (RequestMetadata -> Maybe EventInfo)
-> (RequestMetadata -> Maybe EventInfo -> RequestMetadata)
-> Lens
     RequestMetadata RequestMetadata (Maybe EventInfo) (Maybe EventInfo)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestMetadata' {Maybe EventInfo
eventInfo :: Maybe EventInfo
$sel:eventInfo:RequestMetadata' :: RequestMetadata -> Maybe EventInfo
eventInfo} -> Maybe EventInfo
eventInfo) (\s :: RequestMetadata
s@RequestMetadata' {} Maybe EventInfo
a -> RequestMetadata
s {$sel:eventInfo:RequestMetadata' :: Maybe EventInfo
eventInfo = Maybe EventInfo
a} :: RequestMetadata)

-- | The name of the repository vendor used to upload code to an S3 bucket
-- for a CI\/CD code review. For example, if code and artifacts are
-- uploaded to an S3 bucket for a CI\/CD code review by GitHub scripts from
-- a GitHub repository, then the repository association\'s @ProviderType@
-- is @S3Bucket@ and the CI\/CD repository vendor name is GitHub. For more
-- information, see the definition for @ProviderType@ in
-- <https://docs.aws.amazon.com/codeguru/latest/reviewer-api/API_RepositoryAssociation.html RepositoryAssociation>.
requestMetadata_vendorName :: Lens.Lens' RequestMetadata (Prelude.Maybe VendorName)
requestMetadata_vendorName :: (Maybe VendorName -> f (Maybe VendorName))
-> RequestMetadata -> f RequestMetadata
requestMetadata_vendorName = (RequestMetadata -> Maybe VendorName)
-> (RequestMetadata -> Maybe VendorName -> RequestMetadata)
-> Lens
     RequestMetadata
     RequestMetadata
     (Maybe VendorName)
     (Maybe VendorName)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestMetadata' {Maybe VendorName
vendorName :: Maybe VendorName
$sel:vendorName:RequestMetadata' :: RequestMetadata -> Maybe VendorName
vendorName} -> Maybe VendorName
vendorName) (\s :: RequestMetadata
s@RequestMetadata' {} Maybe VendorName
a -> RequestMetadata
s {$sel:vendorName:RequestMetadata' :: Maybe VendorName
vendorName = Maybe VendorName
a} :: RequestMetadata)

-- | An identifier, such as a name or account ID, that is associated with the
-- requester. The @Requester@ is used to capture the @author\/actor@ name
-- of the event request.
requestMetadata_requester :: Lens.Lens' RequestMetadata (Prelude.Maybe Prelude.Text)
requestMetadata_requester :: (Maybe Text -> f (Maybe Text))
-> RequestMetadata -> f RequestMetadata
requestMetadata_requester = (RequestMetadata -> Maybe Text)
-> (RequestMetadata -> Maybe Text -> RequestMetadata)
-> Lens RequestMetadata RequestMetadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestMetadata' {Maybe Text
requester :: Maybe Text
$sel:requester:RequestMetadata' :: RequestMetadata -> Maybe Text
requester} -> Maybe Text
requester) (\s :: RequestMetadata
s@RequestMetadata' {} Maybe Text
a -> RequestMetadata
s {$sel:requester:RequestMetadata' :: Maybe Text
requester = Maybe Text
a} :: RequestMetadata)

instance Core.FromJSON RequestMetadata where
  parseJSON :: Value -> Parser RequestMetadata
parseJSON =
    String
-> (Object -> Parser RequestMetadata)
-> Value
-> Parser RequestMetadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RequestMetadata"
      ( \Object
x ->
          Maybe Text
-> Maybe EventInfo
-> Maybe VendorName
-> Maybe Text
-> RequestMetadata
RequestMetadata'
            (Maybe Text
 -> Maybe EventInfo
 -> Maybe VendorName
 -> Maybe Text
 -> RequestMetadata)
-> Parser (Maybe Text)
-> Parser
     (Maybe EventInfo
      -> Maybe VendorName -> Maybe Text -> RequestMetadata)
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
"RequestId")
            Parser
  (Maybe EventInfo
   -> Maybe VendorName -> Maybe Text -> RequestMetadata)
-> Parser (Maybe EventInfo)
-> Parser (Maybe VendorName -> Maybe Text -> RequestMetadata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EventInfo)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EventInfo")
            Parser (Maybe VendorName -> Maybe Text -> RequestMetadata)
-> Parser (Maybe VendorName)
-> Parser (Maybe Text -> RequestMetadata)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe VendorName)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"VendorName")
            Parser (Maybe Text -> RequestMetadata)
-> Parser (Maybe Text) -> Parser RequestMetadata
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
"Requester")
      )

instance Prelude.Hashable RequestMetadata

instance Prelude.NFData RequestMetadata

instance Core.ToJSON RequestMetadata where
  toJSON :: RequestMetadata -> Value
toJSON RequestMetadata' {Maybe Text
Maybe EventInfo
Maybe VendorName
requester :: Maybe Text
vendorName :: Maybe VendorName
eventInfo :: Maybe EventInfo
requestId :: Maybe Text
$sel:requester:RequestMetadata' :: RequestMetadata -> Maybe Text
$sel:vendorName:RequestMetadata' :: RequestMetadata -> Maybe VendorName
$sel:eventInfo:RequestMetadata' :: RequestMetadata -> Maybe EventInfo
$sel:requestId:RequestMetadata' :: RequestMetadata -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RequestId" 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
requestId,
            (Text
"EventInfo" Text -> EventInfo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EventInfo -> Pair) -> Maybe EventInfo -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EventInfo
eventInfo,
            (Text
"VendorName" Text -> VendorName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (VendorName -> Pair) -> Maybe VendorName -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe VendorName
vendorName,
            (Text
"Requester" 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
requester
          ]
      )