{-# 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.SSMContacts.PutContactPolicy
-- 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)
--
-- Adds a resource to the specified contact or escalation plan.
module Amazonka.SSMContacts.PutContactPolicy
  ( -- * Creating a Request
    PutContactPolicy (..),
    newPutContactPolicy,

    -- * Request Lenses
    putContactPolicy_contactArn,
    putContactPolicy_policy,

    -- * Destructuring the Response
    PutContactPolicyResponse (..),
    newPutContactPolicyResponse,

    -- * Response Lenses
    putContactPolicyResponse_httpStatus,
  )
where

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
import Amazonka.SSMContacts.Types

-- | /See:/ 'newPutContactPolicy' smart constructor.
data PutContactPolicy = PutContactPolicy'
  { -- | The Amazon Resource Name (ARN) of the contact or escalation plan.
    PutContactPolicy -> Text
contactArn :: Prelude.Text,
    -- | Details of the resource policy.
    PutContactPolicy -> Text
policy :: Prelude.Text
  }
  deriving (PutContactPolicy -> PutContactPolicy -> Bool
(PutContactPolicy -> PutContactPolicy -> Bool)
-> (PutContactPolicy -> PutContactPolicy -> Bool)
-> Eq PutContactPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutContactPolicy -> PutContactPolicy -> Bool
$c/= :: PutContactPolicy -> PutContactPolicy -> Bool
== :: PutContactPolicy -> PutContactPolicy -> Bool
$c== :: PutContactPolicy -> PutContactPolicy -> Bool
Prelude.Eq, ReadPrec [PutContactPolicy]
ReadPrec PutContactPolicy
Int -> ReadS PutContactPolicy
ReadS [PutContactPolicy]
(Int -> ReadS PutContactPolicy)
-> ReadS [PutContactPolicy]
-> ReadPrec PutContactPolicy
-> ReadPrec [PutContactPolicy]
-> Read PutContactPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutContactPolicy]
$creadListPrec :: ReadPrec [PutContactPolicy]
readPrec :: ReadPrec PutContactPolicy
$creadPrec :: ReadPrec PutContactPolicy
readList :: ReadS [PutContactPolicy]
$creadList :: ReadS [PutContactPolicy]
readsPrec :: Int -> ReadS PutContactPolicy
$creadsPrec :: Int -> ReadS PutContactPolicy
Prelude.Read, Int -> PutContactPolicy -> ShowS
[PutContactPolicy] -> ShowS
PutContactPolicy -> String
(Int -> PutContactPolicy -> ShowS)
-> (PutContactPolicy -> String)
-> ([PutContactPolicy] -> ShowS)
-> Show PutContactPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutContactPolicy] -> ShowS
$cshowList :: [PutContactPolicy] -> ShowS
show :: PutContactPolicy -> String
$cshow :: PutContactPolicy -> String
showsPrec :: Int -> PutContactPolicy -> ShowS
$cshowsPrec :: Int -> PutContactPolicy -> ShowS
Prelude.Show, (forall x. PutContactPolicy -> Rep PutContactPolicy x)
-> (forall x. Rep PutContactPolicy x -> PutContactPolicy)
-> Generic PutContactPolicy
forall x. Rep PutContactPolicy x -> PutContactPolicy
forall x. PutContactPolicy -> Rep PutContactPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutContactPolicy x -> PutContactPolicy
$cfrom :: forall x. PutContactPolicy -> Rep PutContactPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutContactPolicy' 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:
--
-- 'contactArn', 'putContactPolicy_contactArn' - The Amazon Resource Name (ARN) of the contact or escalation plan.
--
-- 'policy', 'putContactPolicy_policy' - Details of the resource policy.
newPutContactPolicy ::
  -- | 'contactArn'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  PutContactPolicy
newPutContactPolicy :: Text -> Text -> PutContactPolicy
newPutContactPolicy Text
pContactArn_ Text
pPolicy_ =
  PutContactPolicy' :: Text -> Text -> PutContactPolicy
PutContactPolicy'
    { $sel:contactArn:PutContactPolicy' :: Text
contactArn = Text
pContactArn_,
      $sel:policy:PutContactPolicy' :: Text
policy = Text
pPolicy_
    }

-- | The Amazon Resource Name (ARN) of the contact or escalation plan.
putContactPolicy_contactArn :: Lens.Lens' PutContactPolicy Prelude.Text
putContactPolicy_contactArn :: (Text -> f Text) -> PutContactPolicy -> f PutContactPolicy
putContactPolicy_contactArn = (PutContactPolicy -> Text)
-> (PutContactPolicy -> Text -> PutContactPolicy)
-> Lens PutContactPolicy PutContactPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutContactPolicy' {Text
contactArn :: Text
$sel:contactArn:PutContactPolicy' :: PutContactPolicy -> Text
contactArn} -> Text
contactArn) (\s :: PutContactPolicy
s@PutContactPolicy' {} Text
a -> PutContactPolicy
s {$sel:contactArn:PutContactPolicy' :: Text
contactArn = Text
a} :: PutContactPolicy)

-- | Details of the resource policy.
putContactPolicy_policy :: Lens.Lens' PutContactPolicy Prelude.Text
putContactPolicy_policy :: (Text -> f Text) -> PutContactPolicy -> f PutContactPolicy
putContactPolicy_policy = (PutContactPolicy -> Text)
-> (PutContactPolicy -> Text -> PutContactPolicy)
-> Lens PutContactPolicy PutContactPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutContactPolicy' {Text
policy :: Text
$sel:policy:PutContactPolicy' :: PutContactPolicy -> Text
policy} -> Text
policy) (\s :: PutContactPolicy
s@PutContactPolicy' {} Text
a -> PutContactPolicy
s {$sel:policy:PutContactPolicy' :: Text
policy = Text
a} :: PutContactPolicy)

instance Core.AWSRequest PutContactPolicy where
  type
    AWSResponse PutContactPolicy =
      PutContactPolicyResponse
  request :: PutContactPolicy -> Request PutContactPolicy
request = Service -> PutContactPolicy -> Request PutContactPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutContactPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutContactPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutContactPolicy))
-> Logger
-> Service
-> Proxy PutContactPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutContactPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutContactPolicyResponse
PutContactPolicyResponse'
            (Int -> PutContactPolicyResponse)
-> Either String Int -> Either String PutContactPolicyResponse
forall (f :: * -> *) a b. Functor 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 PutContactPolicy

instance Prelude.NFData PutContactPolicy

instance Core.ToHeaders PutContactPolicy where
  toHeaders :: PutContactPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutContactPolicy -> 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
"SSMContacts.PutContactPolicy" ::
                          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 PutContactPolicy where
  toJSON :: PutContactPolicy -> Value
toJSON PutContactPolicy' {Text
policy :: Text
contactArn :: Text
$sel:policy:PutContactPolicy' :: PutContactPolicy -> Text
$sel:contactArn:PutContactPolicy' :: PutContactPolicy -> 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
"ContactArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
contactArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Policy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policy)
          ]
      )

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

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

-- | /See:/ 'newPutContactPolicyResponse' smart constructor.
data PutContactPolicyResponse = PutContactPolicyResponse'
  { -- | The response's http status code.
    PutContactPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutContactPolicyResponse -> PutContactPolicyResponse -> Bool
(PutContactPolicyResponse -> PutContactPolicyResponse -> Bool)
-> (PutContactPolicyResponse -> PutContactPolicyResponse -> Bool)
-> Eq PutContactPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutContactPolicyResponse -> PutContactPolicyResponse -> Bool
$c/= :: PutContactPolicyResponse -> PutContactPolicyResponse -> Bool
== :: PutContactPolicyResponse -> PutContactPolicyResponse -> Bool
$c== :: PutContactPolicyResponse -> PutContactPolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutContactPolicyResponse]
ReadPrec PutContactPolicyResponse
Int -> ReadS PutContactPolicyResponse
ReadS [PutContactPolicyResponse]
(Int -> ReadS PutContactPolicyResponse)
-> ReadS [PutContactPolicyResponse]
-> ReadPrec PutContactPolicyResponse
-> ReadPrec [PutContactPolicyResponse]
-> Read PutContactPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutContactPolicyResponse]
$creadListPrec :: ReadPrec [PutContactPolicyResponse]
readPrec :: ReadPrec PutContactPolicyResponse
$creadPrec :: ReadPrec PutContactPolicyResponse
readList :: ReadS [PutContactPolicyResponse]
$creadList :: ReadS [PutContactPolicyResponse]
readsPrec :: Int -> ReadS PutContactPolicyResponse
$creadsPrec :: Int -> ReadS PutContactPolicyResponse
Prelude.Read, Int -> PutContactPolicyResponse -> ShowS
[PutContactPolicyResponse] -> ShowS
PutContactPolicyResponse -> String
(Int -> PutContactPolicyResponse -> ShowS)
-> (PutContactPolicyResponse -> String)
-> ([PutContactPolicyResponse] -> ShowS)
-> Show PutContactPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutContactPolicyResponse] -> ShowS
$cshowList :: [PutContactPolicyResponse] -> ShowS
show :: PutContactPolicyResponse -> String
$cshow :: PutContactPolicyResponse -> String
showsPrec :: Int -> PutContactPolicyResponse -> ShowS
$cshowsPrec :: Int -> PutContactPolicyResponse -> ShowS
Prelude.Show, (forall x.
 PutContactPolicyResponse -> Rep PutContactPolicyResponse x)
-> (forall x.
    Rep PutContactPolicyResponse x -> PutContactPolicyResponse)
-> Generic PutContactPolicyResponse
forall x.
Rep PutContactPolicyResponse x -> PutContactPolicyResponse
forall x.
PutContactPolicyResponse -> Rep PutContactPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutContactPolicyResponse x -> PutContactPolicyResponse
$cfrom :: forall x.
PutContactPolicyResponse -> Rep PutContactPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutContactPolicyResponse' 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:
--
-- 'httpStatus', 'putContactPolicyResponse_httpStatus' - The response's http status code.
newPutContactPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutContactPolicyResponse
newPutContactPolicyResponse :: Int -> PutContactPolicyResponse
newPutContactPolicyResponse Int
pHttpStatus_ =
  PutContactPolicyResponse' :: Int -> PutContactPolicyResponse
PutContactPolicyResponse'
    { $sel:httpStatus:PutContactPolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData PutContactPolicyResponse