{-# 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.IAM.Types.RoleUsageType
-- 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.IAM.Types.RoleUsageType where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that contains details about how a service-linked role is used,
-- if that information is returned by the service.
--
-- This data type is used as a response element in the
-- GetServiceLinkedRoleDeletionStatus operation.
--
-- /See:/ 'newRoleUsageType' smart constructor.
data RoleUsageType = RoleUsageType'
  { -- | The name of the resource that is using the service-linked role.
    RoleUsageType -> Maybe [Text]
resources :: Prelude.Maybe [Prelude.Text],
    -- | The name of the Region where the service-linked role is being used.
    RoleUsageType -> Maybe Text
region :: Prelude.Maybe Prelude.Text
  }
  deriving (RoleUsageType -> RoleUsageType -> Bool
(RoleUsageType -> RoleUsageType -> Bool)
-> (RoleUsageType -> RoleUsageType -> Bool) -> Eq RoleUsageType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RoleUsageType -> RoleUsageType -> Bool
$c/= :: RoleUsageType -> RoleUsageType -> Bool
== :: RoleUsageType -> RoleUsageType -> Bool
$c== :: RoleUsageType -> RoleUsageType -> Bool
Prelude.Eq, ReadPrec [RoleUsageType]
ReadPrec RoleUsageType
Int -> ReadS RoleUsageType
ReadS [RoleUsageType]
(Int -> ReadS RoleUsageType)
-> ReadS [RoleUsageType]
-> ReadPrec RoleUsageType
-> ReadPrec [RoleUsageType]
-> Read RoleUsageType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RoleUsageType]
$creadListPrec :: ReadPrec [RoleUsageType]
readPrec :: ReadPrec RoleUsageType
$creadPrec :: ReadPrec RoleUsageType
readList :: ReadS [RoleUsageType]
$creadList :: ReadS [RoleUsageType]
readsPrec :: Int -> ReadS RoleUsageType
$creadsPrec :: Int -> ReadS RoleUsageType
Prelude.Read, Int -> RoleUsageType -> ShowS
[RoleUsageType] -> ShowS
RoleUsageType -> String
(Int -> RoleUsageType -> ShowS)
-> (RoleUsageType -> String)
-> ([RoleUsageType] -> ShowS)
-> Show RoleUsageType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoleUsageType] -> ShowS
$cshowList :: [RoleUsageType] -> ShowS
show :: RoleUsageType -> String
$cshow :: RoleUsageType -> String
showsPrec :: Int -> RoleUsageType -> ShowS
$cshowsPrec :: Int -> RoleUsageType -> ShowS
Prelude.Show, (forall x. RoleUsageType -> Rep RoleUsageType x)
-> (forall x. Rep RoleUsageType x -> RoleUsageType)
-> Generic RoleUsageType
forall x. Rep RoleUsageType x -> RoleUsageType
forall x. RoleUsageType -> Rep RoleUsageType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RoleUsageType x -> RoleUsageType
$cfrom :: forall x. RoleUsageType -> Rep RoleUsageType x
Prelude.Generic)

-- |
-- Create a value of 'RoleUsageType' 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:
--
-- 'resources', 'roleUsageType_resources' - The name of the resource that is using the service-linked role.
--
-- 'region', 'roleUsageType_region' - The name of the Region where the service-linked role is being used.
newRoleUsageType ::
  RoleUsageType
newRoleUsageType :: RoleUsageType
newRoleUsageType =
  RoleUsageType' :: Maybe [Text] -> Maybe Text -> RoleUsageType
RoleUsageType'
    { $sel:resources:RoleUsageType' :: Maybe [Text]
resources = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:region:RoleUsageType' :: Maybe Text
region = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the resource that is using the service-linked role.
roleUsageType_resources :: Lens.Lens' RoleUsageType (Prelude.Maybe [Prelude.Text])
roleUsageType_resources :: (Maybe [Text] -> f (Maybe [Text]))
-> RoleUsageType -> f RoleUsageType
roleUsageType_resources = (RoleUsageType -> Maybe [Text])
-> (RoleUsageType -> Maybe [Text] -> RoleUsageType)
-> Lens RoleUsageType RoleUsageType (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoleUsageType' {Maybe [Text]
resources :: Maybe [Text]
$sel:resources:RoleUsageType' :: RoleUsageType -> Maybe [Text]
resources} -> Maybe [Text]
resources) (\s :: RoleUsageType
s@RoleUsageType' {} Maybe [Text]
a -> RoleUsageType
s {$sel:resources:RoleUsageType' :: Maybe [Text]
resources = Maybe [Text]
a} :: RoleUsageType) ((Maybe [Text] -> f (Maybe [Text]))
 -> RoleUsageType -> f RoleUsageType)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> RoleUsageType
-> f RoleUsageType
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the Region where the service-linked role is being used.
roleUsageType_region :: Lens.Lens' RoleUsageType (Prelude.Maybe Prelude.Text)
roleUsageType_region :: (Maybe Text -> f (Maybe Text)) -> RoleUsageType -> f RoleUsageType
roleUsageType_region = (RoleUsageType -> Maybe Text)
-> (RoleUsageType -> Maybe Text -> RoleUsageType)
-> Lens RoleUsageType RoleUsageType (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoleUsageType' {Maybe Text
region :: Maybe Text
$sel:region:RoleUsageType' :: RoleUsageType -> Maybe Text
region} -> Maybe Text
region) (\s :: RoleUsageType
s@RoleUsageType' {} Maybe Text
a -> RoleUsageType
s {$sel:region:RoleUsageType' :: Maybe Text
region = Maybe Text
a} :: RoleUsageType)

instance Core.FromXML RoleUsageType where
  parseXML :: [Node] -> Either String RoleUsageType
parseXML [Node]
x =
    Maybe [Text] -> Maybe Text -> RoleUsageType
RoleUsageType'
      (Maybe [Text] -> Maybe Text -> RoleUsageType)
-> Either String (Maybe [Text])
-> Either String (Maybe Text -> RoleUsageType)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Resources" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either String (Maybe Text -> RoleUsageType)
-> Either String (Maybe Text) -> Either String RoleUsageType
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Region")

instance Prelude.Hashable RoleUsageType

instance Prelude.NFData RoleUsageType