{-# 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.WorkMail.ListAccessControlRules
-- 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)
--
-- Lists the access control rules for the specified organization.
module Amazonka.WorkMail.ListAccessControlRules
  ( -- * Creating a Request
    ListAccessControlRules (..),
    newListAccessControlRules,

    -- * Request Lenses
    listAccessControlRules_organizationId,

    -- * Destructuring the Response
    ListAccessControlRulesResponse (..),
    newListAccessControlRulesResponse,

    -- * Response Lenses
    listAccessControlRulesResponse_rules,
    listAccessControlRulesResponse_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.WorkMail.Types

-- | /See:/ 'newListAccessControlRules' smart constructor.
data ListAccessControlRules = ListAccessControlRules'
  { -- | The identifier for the organization.
    ListAccessControlRules -> Text
organizationId :: Prelude.Text
  }
  deriving (ListAccessControlRules -> ListAccessControlRules -> Bool
(ListAccessControlRules -> ListAccessControlRules -> Bool)
-> (ListAccessControlRules -> ListAccessControlRules -> Bool)
-> Eq ListAccessControlRules
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAccessControlRules -> ListAccessControlRules -> Bool
$c/= :: ListAccessControlRules -> ListAccessControlRules -> Bool
== :: ListAccessControlRules -> ListAccessControlRules -> Bool
$c== :: ListAccessControlRules -> ListAccessControlRules -> Bool
Prelude.Eq, ReadPrec [ListAccessControlRules]
ReadPrec ListAccessControlRules
Int -> ReadS ListAccessControlRules
ReadS [ListAccessControlRules]
(Int -> ReadS ListAccessControlRules)
-> ReadS [ListAccessControlRules]
-> ReadPrec ListAccessControlRules
-> ReadPrec [ListAccessControlRules]
-> Read ListAccessControlRules
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListAccessControlRules]
$creadListPrec :: ReadPrec [ListAccessControlRules]
readPrec :: ReadPrec ListAccessControlRules
$creadPrec :: ReadPrec ListAccessControlRules
readList :: ReadS [ListAccessControlRules]
$creadList :: ReadS [ListAccessControlRules]
readsPrec :: Int -> ReadS ListAccessControlRules
$creadsPrec :: Int -> ReadS ListAccessControlRules
Prelude.Read, Int -> ListAccessControlRules -> ShowS
[ListAccessControlRules] -> ShowS
ListAccessControlRules -> String
(Int -> ListAccessControlRules -> ShowS)
-> (ListAccessControlRules -> String)
-> ([ListAccessControlRules] -> ShowS)
-> Show ListAccessControlRules
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAccessControlRules] -> ShowS
$cshowList :: [ListAccessControlRules] -> ShowS
show :: ListAccessControlRules -> String
$cshow :: ListAccessControlRules -> String
showsPrec :: Int -> ListAccessControlRules -> ShowS
$cshowsPrec :: Int -> ListAccessControlRules -> ShowS
Prelude.Show, (forall x. ListAccessControlRules -> Rep ListAccessControlRules x)
-> (forall x.
    Rep ListAccessControlRules x -> ListAccessControlRules)
-> Generic ListAccessControlRules
forall x. Rep ListAccessControlRules x -> ListAccessControlRules
forall x. ListAccessControlRules -> Rep ListAccessControlRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListAccessControlRules x -> ListAccessControlRules
$cfrom :: forall x. ListAccessControlRules -> Rep ListAccessControlRules x
Prelude.Generic)

-- |
-- Create a value of 'ListAccessControlRules' 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:
--
-- 'organizationId', 'listAccessControlRules_organizationId' - The identifier for the organization.
newListAccessControlRules ::
  -- | 'organizationId'
  Prelude.Text ->
  ListAccessControlRules
newListAccessControlRules :: Text -> ListAccessControlRules
newListAccessControlRules Text
pOrganizationId_ =
  ListAccessControlRules' :: Text -> ListAccessControlRules
ListAccessControlRules'
    { $sel:organizationId:ListAccessControlRules' :: Text
organizationId =
        Text
pOrganizationId_
    }

-- | The identifier for the organization.
listAccessControlRules_organizationId :: Lens.Lens' ListAccessControlRules Prelude.Text
listAccessControlRules_organizationId :: (Text -> f Text)
-> ListAccessControlRules -> f ListAccessControlRules
listAccessControlRules_organizationId = (ListAccessControlRules -> Text)
-> (ListAccessControlRules -> Text -> ListAccessControlRules)
-> Lens ListAccessControlRules ListAccessControlRules Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAccessControlRules' {Text
organizationId :: Text
$sel:organizationId:ListAccessControlRules' :: ListAccessControlRules -> Text
organizationId} -> Text
organizationId) (\s :: ListAccessControlRules
s@ListAccessControlRules' {} Text
a -> ListAccessControlRules
s {$sel:organizationId:ListAccessControlRules' :: Text
organizationId = Text
a} :: ListAccessControlRules)

instance Core.AWSRequest ListAccessControlRules where
  type
    AWSResponse ListAccessControlRules =
      ListAccessControlRulesResponse
  request :: ListAccessControlRules -> Request ListAccessControlRules
request = Service -> ListAccessControlRules -> Request ListAccessControlRules
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ListAccessControlRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListAccessControlRules)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListAccessControlRules))
-> Logger
-> Service
-> Proxy ListAccessControlRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListAccessControlRules)))
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 [AccessControlRule] -> Int -> ListAccessControlRulesResponse
ListAccessControlRulesResponse'
            (Maybe [AccessControlRule]
 -> Int -> ListAccessControlRulesResponse)
-> Either String (Maybe [AccessControlRule])
-> Either String (Int -> ListAccessControlRulesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [AccessControlRule]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Rules" Either String (Maybe (Maybe [AccessControlRule]))
-> Maybe [AccessControlRule]
-> Either String (Maybe [AccessControlRule])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [AccessControlRule]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ListAccessControlRulesResponse)
-> Either String Int
-> Either String ListAccessControlRulesResponse
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 ListAccessControlRules

instance Prelude.NFData ListAccessControlRules

instance Core.ToHeaders ListAccessControlRules where
  toHeaders :: ListAccessControlRules -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ListAccessControlRules -> 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
"WorkMailService.ListAccessControlRules" ::
                          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 ListAccessControlRules where
  toJSON :: ListAccessControlRules -> Value
toJSON ListAccessControlRules' {Text
organizationId :: Text
$sel:organizationId:ListAccessControlRules' :: ListAccessControlRules -> 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
"OrganizationId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
organizationId)
          ]
      )

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

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

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

-- |
-- Create a value of 'ListAccessControlRulesResponse' 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:
--
-- 'rules', 'listAccessControlRulesResponse_rules' - The access control rules.
--
-- 'httpStatus', 'listAccessControlRulesResponse_httpStatus' - The response's http status code.
newListAccessControlRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListAccessControlRulesResponse
newListAccessControlRulesResponse :: Int -> ListAccessControlRulesResponse
newListAccessControlRulesResponse Int
pHttpStatus_ =
  ListAccessControlRulesResponse' :: Maybe [AccessControlRule] -> Int -> ListAccessControlRulesResponse
ListAccessControlRulesResponse'
    { $sel:rules:ListAccessControlRulesResponse' :: Maybe [AccessControlRule]
rules =
        Maybe [AccessControlRule]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListAccessControlRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The access control rules.
listAccessControlRulesResponse_rules :: Lens.Lens' ListAccessControlRulesResponse (Prelude.Maybe [AccessControlRule])
listAccessControlRulesResponse_rules :: (Maybe [AccessControlRule] -> f (Maybe [AccessControlRule]))
-> ListAccessControlRulesResponse
-> f ListAccessControlRulesResponse
listAccessControlRulesResponse_rules = (ListAccessControlRulesResponse -> Maybe [AccessControlRule])
-> (ListAccessControlRulesResponse
    -> Maybe [AccessControlRule] -> ListAccessControlRulesResponse)
-> Lens
     ListAccessControlRulesResponse
     ListAccessControlRulesResponse
     (Maybe [AccessControlRule])
     (Maybe [AccessControlRule])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAccessControlRulesResponse' {Maybe [AccessControlRule]
rules :: Maybe [AccessControlRule]
$sel:rules:ListAccessControlRulesResponse' :: ListAccessControlRulesResponse -> Maybe [AccessControlRule]
rules} -> Maybe [AccessControlRule]
rules) (\s :: ListAccessControlRulesResponse
s@ListAccessControlRulesResponse' {} Maybe [AccessControlRule]
a -> ListAccessControlRulesResponse
s {$sel:rules:ListAccessControlRulesResponse' :: Maybe [AccessControlRule]
rules = Maybe [AccessControlRule]
a} :: ListAccessControlRulesResponse) ((Maybe [AccessControlRule] -> f (Maybe [AccessControlRule]))
 -> ListAccessControlRulesResponse
 -> f ListAccessControlRulesResponse)
-> ((Maybe [AccessControlRule] -> f (Maybe [AccessControlRule]))
    -> Maybe [AccessControlRule] -> f (Maybe [AccessControlRule]))
-> (Maybe [AccessControlRule] -> f (Maybe [AccessControlRule]))
-> ListAccessControlRulesResponse
-> f ListAccessControlRulesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [AccessControlRule]
  [AccessControlRule]
  [AccessControlRule]
  [AccessControlRule]
-> Iso
     (Maybe [AccessControlRule])
     (Maybe [AccessControlRule])
     (Maybe [AccessControlRule])
     (Maybe [AccessControlRule])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [AccessControlRule]
  [AccessControlRule]
  [AccessControlRule]
  [AccessControlRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    ListAccessControlRulesResponse