{-# 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.SES.CreateReceiptRule
-- 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)
--
-- Creates a receipt rule.
--
-- For information about setting up receipt rules, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-receipt-rules.html Amazon SES Developer Guide>.
--
-- You can execute this operation no more than once per second.
module Amazonka.SES.CreateReceiptRule
  ( -- * Creating a Request
    CreateReceiptRule (..),
    newCreateReceiptRule,

    -- * Request Lenses
    createReceiptRule_after,
    createReceiptRule_ruleSetName,
    createReceiptRule_rule,

    -- * Destructuring the Response
    CreateReceiptRuleResponse (..),
    newCreateReceiptRuleResponse,

    -- * Response Lenses
    createReceiptRuleResponse_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.SES.Types

-- | Represents a request to create a receipt rule. You use receipt rules to
-- receive email with Amazon SES. For more information, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-concepts.html Amazon SES Developer Guide>.
--
-- /See:/ 'newCreateReceiptRule' smart constructor.
data CreateReceiptRule = CreateReceiptRule'
  { -- | The name of an existing rule after which the new rule will be placed. If
    -- this parameter is null, the new rule will be inserted at the beginning
    -- of the rule list.
    CreateReceiptRule -> Maybe Text
after :: Prelude.Maybe Prelude.Text,
    -- | The name of the rule set that the receipt rule will be added to.
    CreateReceiptRule -> Text
ruleSetName :: Prelude.Text,
    -- | A data structure that contains the specified rule\'s name, actions,
    -- recipients, domains, enabled status, scan status, and TLS policy.
    CreateReceiptRule -> ReceiptRule
rule :: ReceiptRule
  }
  deriving (CreateReceiptRule -> CreateReceiptRule -> Bool
(CreateReceiptRule -> CreateReceiptRule -> Bool)
-> (CreateReceiptRule -> CreateReceiptRule -> Bool)
-> Eq CreateReceiptRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateReceiptRule -> CreateReceiptRule -> Bool
$c/= :: CreateReceiptRule -> CreateReceiptRule -> Bool
== :: CreateReceiptRule -> CreateReceiptRule -> Bool
$c== :: CreateReceiptRule -> CreateReceiptRule -> Bool
Prelude.Eq, ReadPrec [CreateReceiptRule]
ReadPrec CreateReceiptRule
Int -> ReadS CreateReceiptRule
ReadS [CreateReceiptRule]
(Int -> ReadS CreateReceiptRule)
-> ReadS [CreateReceiptRule]
-> ReadPrec CreateReceiptRule
-> ReadPrec [CreateReceiptRule]
-> Read CreateReceiptRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateReceiptRule]
$creadListPrec :: ReadPrec [CreateReceiptRule]
readPrec :: ReadPrec CreateReceiptRule
$creadPrec :: ReadPrec CreateReceiptRule
readList :: ReadS [CreateReceiptRule]
$creadList :: ReadS [CreateReceiptRule]
readsPrec :: Int -> ReadS CreateReceiptRule
$creadsPrec :: Int -> ReadS CreateReceiptRule
Prelude.Read, Int -> CreateReceiptRule -> ShowS
[CreateReceiptRule] -> ShowS
CreateReceiptRule -> String
(Int -> CreateReceiptRule -> ShowS)
-> (CreateReceiptRule -> String)
-> ([CreateReceiptRule] -> ShowS)
-> Show CreateReceiptRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateReceiptRule] -> ShowS
$cshowList :: [CreateReceiptRule] -> ShowS
show :: CreateReceiptRule -> String
$cshow :: CreateReceiptRule -> String
showsPrec :: Int -> CreateReceiptRule -> ShowS
$cshowsPrec :: Int -> CreateReceiptRule -> ShowS
Prelude.Show, (forall x. CreateReceiptRule -> Rep CreateReceiptRule x)
-> (forall x. Rep CreateReceiptRule x -> CreateReceiptRule)
-> Generic CreateReceiptRule
forall x. Rep CreateReceiptRule x -> CreateReceiptRule
forall x. CreateReceiptRule -> Rep CreateReceiptRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateReceiptRule x -> CreateReceiptRule
$cfrom :: forall x. CreateReceiptRule -> Rep CreateReceiptRule x
Prelude.Generic)

-- |
-- Create a value of 'CreateReceiptRule' 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:
--
-- 'after', 'createReceiptRule_after' - The name of an existing rule after which the new rule will be placed. If
-- this parameter is null, the new rule will be inserted at the beginning
-- of the rule list.
--
-- 'ruleSetName', 'createReceiptRule_ruleSetName' - The name of the rule set that the receipt rule will be added to.
--
-- 'rule', 'createReceiptRule_rule' - A data structure that contains the specified rule\'s name, actions,
-- recipients, domains, enabled status, scan status, and TLS policy.
newCreateReceiptRule ::
  -- | 'ruleSetName'
  Prelude.Text ->
  -- | 'rule'
  ReceiptRule ->
  CreateReceiptRule
newCreateReceiptRule :: Text -> ReceiptRule -> CreateReceiptRule
newCreateReceiptRule Text
pRuleSetName_ ReceiptRule
pRule_ =
  CreateReceiptRule' :: Maybe Text -> Text -> ReceiptRule -> CreateReceiptRule
CreateReceiptRule'
    { $sel:after:CreateReceiptRule' :: Maybe Text
after = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleSetName:CreateReceiptRule' :: Text
ruleSetName = Text
pRuleSetName_,
      $sel:rule:CreateReceiptRule' :: ReceiptRule
rule = ReceiptRule
pRule_
    }

-- | The name of an existing rule after which the new rule will be placed. If
-- this parameter is null, the new rule will be inserted at the beginning
-- of the rule list.
createReceiptRule_after :: Lens.Lens' CreateReceiptRule (Prelude.Maybe Prelude.Text)
createReceiptRule_after :: (Maybe Text -> f (Maybe Text))
-> CreateReceiptRule -> f CreateReceiptRule
createReceiptRule_after = (CreateReceiptRule -> Maybe Text)
-> (CreateReceiptRule -> Maybe Text -> CreateReceiptRule)
-> Lens
     CreateReceiptRule CreateReceiptRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateReceiptRule' {Maybe Text
after :: Maybe Text
$sel:after:CreateReceiptRule' :: CreateReceiptRule -> Maybe Text
after} -> Maybe Text
after) (\s :: CreateReceiptRule
s@CreateReceiptRule' {} Maybe Text
a -> CreateReceiptRule
s {$sel:after:CreateReceiptRule' :: Maybe Text
after = Maybe Text
a} :: CreateReceiptRule)

-- | The name of the rule set that the receipt rule will be added to.
createReceiptRule_ruleSetName :: Lens.Lens' CreateReceiptRule Prelude.Text
createReceiptRule_ruleSetName :: (Text -> f Text) -> CreateReceiptRule -> f CreateReceiptRule
createReceiptRule_ruleSetName = (CreateReceiptRule -> Text)
-> (CreateReceiptRule -> Text -> CreateReceiptRule)
-> Lens CreateReceiptRule CreateReceiptRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateReceiptRule' {Text
ruleSetName :: Text
$sel:ruleSetName:CreateReceiptRule' :: CreateReceiptRule -> Text
ruleSetName} -> Text
ruleSetName) (\s :: CreateReceiptRule
s@CreateReceiptRule' {} Text
a -> CreateReceiptRule
s {$sel:ruleSetName:CreateReceiptRule' :: Text
ruleSetName = Text
a} :: CreateReceiptRule)

-- | A data structure that contains the specified rule\'s name, actions,
-- recipients, domains, enabled status, scan status, and TLS policy.
createReceiptRule_rule :: Lens.Lens' CreateReceiptRule ReceiptRule
createReceiptRule_rule :: (ReceiptRule -> f ReceiptRule)
-> CreateReceiptRule -> f CreateReceiptRule
createReceiptRule_rule = (CreateReceiptRule -> ReceiptRule)
-> (CreateReceiptRule -> ReceiptRule -> CreateReceiptRule)
-> Lens CreateReceiptRule CreateReceiptRule ReceiptRule ReceiptRule
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateReceiptRule' {ReceiptRule
rule :: ReceiptRule
$sel:rule:CreateReceiptRule' :: CreateReceiptRule -> ReceiptRule
rule} -> ReceiptRule
rule) (\s :: CreateReceiptRule
s@CreateReceiptRule' {} ReceiptRule
a -> CreateReceiptRule
s {$sel:rule:CreateReceiptRule' :: ReceiptRule
rule = ReceiptRule
a} :: CreateReceiptRule)

instance Core.AWSRequest CreateReceiptRule where
  type
    AWSResponse CreateReceiptRule =
      CreateReceiptRuleResponse
  request :: CreateReceiptRule -> Request CreateReceiptRule
request = Service -> CreateReceiptRule -> Request CreateReceiptRule
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateReceiptRule
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateReceiptRule)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse CreateReceiptRule))
-> Logger
-> Service
-> Proxy CreateReceiptRule
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateReceiptRule)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"CreateReceiptRuleResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> CreateReceiptRuleResponse
CreateReceiptRuleResponse'
            (Int -> CreateReceiptRuleResponse)
-> Either String Int -> Either String CreateReceiptRuleResponse
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 CreateReceiptRule

instance Prelude.NFData CreateReceiptRule

instance Core.ToHeaders CreateReceiptRule where
  toHeaders :: CreateReceiptRule -> ResponseHeaders
toHeaders = ResponseHeaders -> CreateReceiptRule -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery CreateReceiptRule where
  toQuery :: CreateReceiptRule -> QueryString
toQuery CreateReceiptRule' {Maybe Text
Text
ReceiptRule
rule :: ReceiptRule
ruleSetName :: Text
after :: Maybe Text
$sel:rule:CreateReceiptRule' :: CreateReceiptRule -> ReceiptRule
$sel:ruleSetName:CreateReceiptRule' :: CreateReceiptRule -> Text
$sel:after:CreateReceiptRule' :: CreateReceiptRule -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"CreateReceiptRule" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-12-01" :: Prelude.ByteString),
        ByteString
"After" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
after,
        ByteString
"RuleSetName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
ruleSetName,
        ByteString
"Rule" ByteString -> ReceiptRule -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ReceiptRule
rule
      ]

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

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

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

instance Prelude.NFData CreateReceiptRuleResponse