{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutRepositoryTriggers
-- 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)
--
-- Replaces all triggers for a repository. Used to create or delete
-- triggers.
module Amazonka.CodeCommit.PutRepositoryTriggers
  ( -- * Creating a Request
    PutRepositoryTriggers (..),
    newPutRepositoryTriggers,

    -- * Request Lenses
    putRepositoryTriggers_repositoryName,
    putRepositoryTriggers_triggers,

    -- * Destructuring the Response
    PutRepositoryTriggersResponse (..),
    newPutRepositoryTriggersResponse,

    -- * Response Lenses
    putRepositoryTriggersResponse_configurationId,
    putRepositoryTriggersResponse_httpStatus,
  )
where

import Amazonka.CodeCommit.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input of a put repository triggers operation.
--
-- /See:/ 'newPutRepositoryTriggers' smart constructor.
data PutRepositoryTriggers = PutRepositoryTriggers'
  { -- | The name of the repository where you want to create or update the
    -- trigger.
    PutRepositoryTriggers -> Text
repositoryName :: Prelude.Text,
    -- | The JSON block of configuration information for each trigger.
    PutRepositoryTriggers -> [RepositoryTrigger]
triggers :: [RepositoryTrigger]
  }
  deriving (PutRepositoryTriggers -> PutRepositoryTriggers -> Bool
(PutRepositoryTriggers -> PutRepositoryTriggers -> Bool)
-> (PutRepositoryTriggers -> PutRepositoryTriggers -> Bool)
-> Eq PutRepositoryTriggers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRepositoryTriggers -> PutRepositoryTriggers -> Bool
$c/= :: PutRepositoryTriggers -> PutRepositoryTriggers -> Bool
== :: PutRepositoryTriggers -> PutRepositoryTriggers -> Bool
$c== :: PutRepositoryTriggers -> PutRepositoryTriggers -> Bool
Prelude.Eq, ReadPrec [PutRepositoryTriggers]
ReadPrec PutRepositoryTriggers
Int -> ReadS PutRepositoryTriggers
ReadS [PutRepositoryTriggers]
(Int -> ReadS PutRepositoryTriggers)
-> ReadS [PutRepositoryTriggers]
-> ReadPrec PutRepositoryTriggers
-> ReadPrec [PutRepositoryTriggers]
-> Read PutRepositoryTriggers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRepositoryTriggers]
$creadListPrec :: ReadPrec [PutRepositoryTriggers]
readPrec :: ReadPrec PutRepositoryTriggers
$creadPrec :: ReadPrec PutRepositoryTriggers
readList :: ReadS [PutRepositoryTriggers]
$creadList :: ReadS [PutRepositoryTriggers]
readsPrec :: Int -> ReadS PutRepositoryTriggers
$creadsPrec :: Int -> ReadS PutRepositoryTriggers
Prelude.Read, Int -> PutRepositoryTriggers -> ShowS
[PutRepositoryTriggers] -> ShowS
PutRepositoryTriggers -> String
(Int -> PutRepositoryTriggers -> ShowS)
-> (PutRepositoryTriggers -> String)
-> ([PutRepositoryTriggers] -> ShowS)
-> Show PutRepositoryTriggers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRepositoryTriggers] -> ShowS
$cshowList :: [PutRepositoryTriggers] -> ShowS
show :: PutRepositoryTriggers -> String
$cshow :: PutRepositoryTriggers -> String
showsPrec :: Int -> PutRepositoryTriggers -> ShowS
$cshowsPrec :: Int -> PutRepositoryTriggers -> ShowS
Prelude.Show, (forall x. PutRepositoryTriggers -> Rep PutRepositoryTriggers x)
-> (forall x. Rep PutRepositoryTriggers x -> PutRepositoryTriggers)
-> Generic PutRepositoryTriggers
forall x. Rep PutRepositoryTriggers x -> PutRepositoryTriggers
forall x. PutRepositoryTriggers -> Rep PutRepositoryTriggers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRepositoryTriggers x -> PutRepositoryTriggers
$cfrom :: forall x. PutRepositoryTriggers -> Rep PutRepositoryTriggers x
Prelude.Generic)

-- |
-- Create a value of 'PutRepositoryTriggers' 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:
--
-- 'repositoryName', 'putRepositoryTriggers_repositoryName' - The name of the repository where you want to create or update the
-- trigger.
--
-- 'triggers', 'putRepositoryTriggers_triggers' - The JSON block of configuration information for each trigger.
newPutRepositoryTriggers ::
  -- | 'repositoryName'
  Prelude.Text ->
  PutRepositoryTriggers
newPutRepositoryTriggers :: Text -> PutRepositoryTriggers
newPutRepositoryTriggers Text
pRepositoryName_ =
  PutRepositoryTriggers' :: Text -> [RepositoryTrigger] -> PutRepositoryTriggers
PutRepositoryTriggers'
    { $sel:repositoryName:PutRepositoryTriggers' :: Text
repositoryName =
        Text
pRepositoryName_,
      $sel:triggers:PutRepositoryTriggers' :: [RepositoryTrigger]
triggers = [RepositoryTrigger]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the repository where you want to create or update the
-- trigger.
putRepositoryTriggers_repositoryName :: Lens.Lens' PutRepositoryTriggers Prelude.Text
putRepositoryTriggers_repositoryName :: (Text -> f Text)
-> PutRepositoryTriggers -> f PutRepositoryTriggers
putRepositoryTriggers_repositoryName = (PutRepositoryTriggers -> Text)
-> (PutRepositoryTriggers -> Text -> PutRepositoryTriggers)
-> Lens PutRepositoryTriggers PutRepositoryTriggers Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRepositoryTriggers' {Text
repositoryName :: Text
$sel:repositoryName:PutRepositoryTriggers' :: PutRepositoryTriggers -> Text
repositoryName} -> Text
repositoryName) (\s :: PutRepositoryTriggers
s@PutRepositoryTriggers' {} Text
a -> PutRepositoryTriggers
s {$sel:repositoryName:PutRepositoryTriggers' :: Text
repositoryName = Text
a} :: PutRepositoryTriggers)

-- | The JSON block of configuration information for each trigger.
putRepositoryTriggers_triggers :: Lens.Lens' PutRepositoryTriggers [RepositoryTrigger]
putRepositoryTriggers_triggers :: ([RepositoryTrigger] -> f [RepositoryTrigger])
-> PutRepositoryTriggers -> f PutRepositoryTriggers
putRepositoryTriggers_triggers = (PutRepositoryTriggers -> [RepositoryTrigger])
-> (PutRepositoryTriggers
    -> [RepositoryTrigger] -> PutRepositoryTriggers)
-> Lens
     PutRepositoryTriggers
     PutRepositoryTriggers
     [RepositoryTrigger]
     [RepositoryTrigger]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRepositoryTriggers' {[RepositoryTrigger]
triggers :: [RepositoryTrigger]
$sel:triggers:PutRepositoryTriggers' :: PutRepositoryTriggers -> [RepositoryTrigger]
triggers} -> [RepositoryTrigger]
triggers) (\s :: PutRepositoryTriggers
s@PutRepositoryTriggers' {} [RepositoryTrigger]
a -> PutRepositoryTriggers
s {$sel:triggers:PutRepositoryTriggers' :: [RepositoryTrigger]
triggers = [RepositoryTrigger]
a} :: PutRepositoryTriggers) (([RepositoryTrigger] -> f [RepositoryTrigger])
 -> PutRepositoryTriggers -> f PutRepositoryTriggers)
-> (([RepositoryTrigger] -> f [RepositoryTrigger])
    -> [RepositoryTrigger] -> f [RepositoryTrigger])
-> ([RepositoryTrigger] -> f [RepositoryTrigger])
-> PutRepositoryTriggers
-> f PutRepositoryTriggers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([RepositoryTrigger] -> f [RepositoryTrigger])
-> [RepositoryTrigger] -> f [RepositoryTrigger]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutRepositoryTriggers where
  type
    AWSResponse PutRepositoryTriggers =
      PutRepositoryTriggersResponse
  request :: PutRepositoryTriggers -> Request PutRepositoryTriggers
request = Service -> PutRepositoryTriggers -> Request PutRepositoryTriggers
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRepositoryTriggers
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRepositoryTriggers)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutRepositoryTriggers))
-> Logger
-> Service
-> Proxy PutRepositoryTriggers
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRepositoryTriggers)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> PutRepositoryTriggersResponse
PutRepositoryTriggersResponse'
            (Maybe Text -> Int -> PutRepositoryTriggersResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PutRepositoryTriggersResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"configurationId")
            Either String (Int -> PutRepositoryTriggersResponse)
-> Either String Int -> Either String PutRepositoryTriggersResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutRepositoryTriggers

instance Prelude.NFData PutRepositoryTriggers

instance Core.ToHeaders PutRepositoryTriggers where
  toHeaders :: PutRepositoryTriggers -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutRepositoryTriggers -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"CodeCommit_20150413.PutRepositoryTriggers" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutRepositoryTriggers where
  toJSON :: PutRepositoryTriggers -> Value
toJSON PutRepositoryTriggers' {[RepositoryTrigger]
Text
triggers :: [RepositoryTrigger]
repositoryName :: Text
$sel:triggers:PutRepositoryTriggers' :: PutRepositoryTriggers -> [RepositoryTrigger]
$sel:repositoryName:PutRepositoryTriggers' :: PutRepositoryTriggers -> Text
..} =
    [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
"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
"triggers" Text -> [RepositoryTrigger] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [RepositoryTrigger]
triggers)
          ]
      )

instance Core.ToPath PutRepositoryTriggers where
  toPath :: PutRepositoryTriggers -> ByteString
toPath = ByteString -> PutRepositoryTriggers -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery PutRepositoryTriggers where
  toQuery :: PutRepositoryTriggers -> QueryString
toQuery = QueryString -> PutRepositoryTriggers -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | Represents the output of a put repository triggers operation.
--
-- /See:/ 'newPutRepositoryTriggersResponse' smart constructor.
data PutRepositoryTriggersResponse = PutRepositoryTriggersResponse'
  { -- | The system-generated unique ID for the create or update operation.
    PutRepositoryTriggersResponse -> Maybe Text
configurationId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    PutRepositoryTriggersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutRepositoryTriggersResponse
-> PutRepositoryTriggersResponse -> Bool
(PutRepositoryTriggersResponse
 -> PutRepositoryTriggersResponse -> Bool)
-> (PutRepositoryTriggersResponse
    -> PutRepositoryTriggersResponse -> Bool)
-> Eq PutRepositoryTriggersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRepositoryTriggersResponse
-> PutRepositoryTriggersResponse -> Bool
$c/= :: PutRepositoryTriggersResponse
-> PutRepositoryTriggersResponse -> Bool
== :: PutRepositoryTriggersResponse
-> PutRepositoryTriggersResponse -> Bool
$c== :: PutRepositoryTriggersResponse
-> PutRepositoryTriggersResponse -> Bool
Prelude.Eq, ReadPrec [PutRepositoryTriggersResponse]
ReadPrec PutRepositoryTriggersResponse
Int -> ReadS PutRepositoryTriggersResponse
ReadS [PutRepositoryTriggersResponse]
(Int -> ReadS PutRepositoryTriggersResponse)
-> ReadS [PutRepositoryTriggersResponse]
-> ReadPrec PutRepositoryTriggersResponse
-> ReadPrec [PutRepositoryTriggersResponse]
-> Read PutRepositoryTriggersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRepositoryTriggersResponse]
$creadListPrec :: ReadPrec [PutRepositoryTriggersResponse]
readPrec :: ReadPrec PutRepositoryTriggersResponse
$creadPrec :: ReadPrec PutRepositoryTriggersResponse
readList :: ReadS [PutRepositoryTriggersResponse]
$creadList :: ReadS [PutRepositoryTriggersResponse]
readsPrec :: Int -> ReadS PutRepositoryTriggersResponse
$creadsPrec :: Int -> ReadS PutRepositoryTriggersResponse
Prelude.Read, Int -> PutRepositoryTriggersResponse -> ShowS
[PutRepositoryTriggersResponse] -> ShowS
PutRepositoryTriggersResponse -> String
(Int -> PutRepositoryTriggersResponse -> ShowS)
-> (PutRepositoryTriggersResponse -> String)
-> ([PutRepositoryTriggersResponse] -> ShowS)
-> Show PutRepositoryTriggersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRepositoryTriggersResponse] -> ShowS
$cshowList :: [PutRepositoryTriggersResponse] -> ShowS
show :: PutRepositoryTriggersResponse -> String
$cshow :: PutRepositoryTriggersResponse -> String
showsPrec :: Int -> PutRepositoryTriggersResponse -> ShowS
$cshowsPrec :: Int -> PutRepositoryTriggersResponse -> ShowS
Prelude.Show, (forall x.
 PutRepositoryTriggersResponse
 -> Rep PutRepositoryTriggersResponse x)
-> (forall x.
    Rep PutRepositoryTriggersResponse x
    -> PutRepositoryTriggersResponse)
-> Generic PutRepositoryTriggersResponse
forall x.
Rep PutRepositoryTriggersResponse x
-> PutRepositoryTriggersResponse
forall x.
PutRepositoryTriggersResponse
-> Rep PutRepositoryTriggersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutRepositoryTriggersResponse x
-> PutRepositoryTriggersResponse
$cfrom :: forall x.
PutRepositoryTriggersResponse
-> Rep PutRepositoryTriggersResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutRepositoryTriggersResponse' 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:
--
-- 'configurationId', 'putRepositoryTriggersResponse_configurationId' - The system-generated unique ID for the create or update operation.
--
-- 'httpStatus', 'putRepositoryTriggersResponse_httpStatus' - The response's http status code.
newPutRepositoryTriggersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutRepositoryTriggersResponse
newPutRepositoryTriggersResponse :: Int -> PutRepositoryTriggersResponse
newPutRepositoryTriggersResponse Int
pHttpStatus_ =
  PutRepositoryTriggersResponse' :: Maybe Text -> Int -> PutRepositoryTriggersResponse
PutRepositoryTriggersResponse'
    { $sel:configurationId:PutRepositoryTriggersResponse' :: Maybe Text
configurationId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutRepositoryTriggersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The system-generated unique ID for the create or update operation.
putRepositoryTriggersResponse_configurationId :: Lens.Lens' PutRepositoryTriggersResponse (Prelude.Maybe Prelude.Text)
putRepositoryTriggersResponse_configurationId :: (Maybe Text -> f (Maybe Text))
-> PutRepositoryTriggersResponse -> f PutRepositoryTriggersResponse
putRepositoryTriggersResponse_configurationId = (PutRepositoryTriggersResponse -> Maybe Text)
-> (PutRepositoryTriggersResponse
    -> Maybe Text -> PutRepositoryTriggersResponse)
-> Lens
     PutRepositoryTriggersResponse
     PutRepositoryTriggersResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRepositoryTriggersResponse' {Maybe Text
configurationId :: Maybe Text
$sel:configurationId:PutRepositoryTriggersResponse' :: PutRepositoryTriggersResponse -> Maybe Text
configurationId} -> Maybe Text
configurationId) (\s :: PutRepositoryTriggersResponse
s@PutRepositoryTriggersResponse' {} Maybe Text
a -> PutRepositoryTriggersResponse
s {$sel:configurationId:PutRepositoryTriggersResponse' :: Maybe Text
configurationId = Maybe Text
a} :: PutRepositoryTriggersResponse)

-- | The response's http status code.
putRepositoryTriggersResponse_httpStatus :: Lens.Lens' PutRepositoryTriggersResponse Prelude.Int
putRepositoryTriggersResponse_httpStatus :: (Int -> f Int)
-> PutRepositoryTriggersResponse -> f PutRepositoryTriggersResponse
putRepositoryTriggersResponse_httpStatus = (PutRepositoryTriggersResponse -> Int)
-> (PutRepositoryTriggersResponse
    -> Int -> PutRepositoryTriggersResponse)
-> Lens
     PutRepositoryTriggersResponse PutRepositoryTriggersResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRepositoryTriggersResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutRepositoryTriggersResponse' :: PutRepositoryTriggersResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutRepositoryTriggersResponse
s@PutRepositoryTriggersResponse' {} Int
a -> PutRepositoryTriggersResponse
s {$sel:httpStatus:PutRepositoryTriggersResponse' :: Int
httpStatus = Int
a} :: PutRepositoryTriggersResponse)

instance Prelude.NFData PutRepositoryTriggersResponse