{-# 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.FMS.Types.ResourceSet
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.FMS.Types.ResourceSet where

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

-- | A set of resources to include in a policy.
--
-- /See:/ 'newResourceSet' smart constructor.
data ResourceSet = ResourceSet'
  { -- | A description of the resource set.
    ResourceSet -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for the resource set. This ID is returned in the
    -- responses to create and list commands. You provide it to operations like
    -- update and delete.
    ResourceSet -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The last time that the resource set was changed.
    ResourceSet -> Maybe POSIX
lastUpdateTime :: Prelude.Maybe Data.POSIX,
    -- | An optional token that you can use for optimistic locking. Firewall
    -- Manager returns a token to your requests that access the resource set.
    -- The token marks the state of the resource set resource at the time of
    -- the request. Update tokens are not allowed when creating a resource set.
    -- After creation, each subsequent update call to the resource set requires
    -- the update token.
    --
    -- To make an unconditional change to the resource set, omit the token in
    -- your update request. Without the token, Firewall Manager performs your
    -- updates regardless of whether the resource set has changed since you
    -- last retrieved it.
    --
    -- To make a conditional change to the resource set, provide the token in
    -- your update request. Firewall Manager uses the token to ensure that the
    -- resource set hasn\'t changed since you last retrieved it. If it has
    -- changed, the operation fails with an @InvalidTokenException@. If this
    -- happens, retrieve the resource set again to get a current copy of it
    -- with a new token. Reapply your changes as needed, then try the operation
    -- again using the new token.
    ResourceSet -> Maybe Text
updateToken :: Prelude.Maybe Prelude.Text,
    -- | The descriptive name of the resource set. You can\'t change the name of
    -- a resource set after you create it.
    ResourceSet -> Text
name :: Prelude.Text,
    -- | Determines the resources that can be associated to the resource set.
    -- Depending on your setting for max results and the number of resource
    -- sets, a single call might not return the full list.
    ResourceSet -> [Text]
resourceTypeList :: [Prelude.Text]
  }
  deriving (ResourceSet -> ResourceSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceSet -> ResourceSet -> Bool
$c/= :: ResourceSet -> ResourceSet -> Bool
== :: ResourceSet -> ResourceSet -> Bool
$c== :: ResourceSet -> ResourceSet -> Bool
Prelude.Eq, ReadPrec [ResourceSet]
ReadPrec ResourceSet
Int -> ReadS ResourceSet
ReadS [ResourceSet]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceSet]
$creadListPrec :: ReadPrec [ResourceSet]
readPrec :: ReadPrec ResourceSet
$creadPrec :: ReadPrec ResourceSet
readList :: ReadS [ResourceSet]
$creadList :: ReadS [ResourceSet]
readsPrec :: Int -> ReadS ResourceSet
$creadsPrec :: Int -> ReadS ResourceSet
Prelude.Read, Int -> ResourceSet -> ShowS
[ResourceSet] -> ShowS
ResourceSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceSet] -> ShowS
$cshowList :: [ResourceSet] -> ShowS
show :: ResourceSet -> String
$cshow :: ResourceSet -> String
showsPrec :: Int -> ResourceSet -> ShowS
$cshowsPrec :: Int -> ResourceSet -> ShowS
Prelude.Show, forall x. Rep ResourceSet x -> ResourceSet
forall x. ResourceSet -> Rep ResourceSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceSet x -> ResourceSet
$cfrom :: forall x. ResourceSet -> Rep ResourceSet x
Prelude.Generic)

-- |
-- Create a value of 'ResourceSet' 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:
--
-- 'description', 'resourceSet_description' - A description of the resource set.
--
-- 'id', 'resourceSet_id' - A unique identifier for the resource set. This ID is returned in the
-- responses to create and list commands. You provide it to operations like
-- update and delete.
--
-- 'lastUpdateTime', 'resourceSet_lastUpdateTime' - The last time that the resource set was changed.
--
-- 'updateToken', 'resourceSet_updateToken' - An optional token that you can use for optimistic locking. Firewall
-- Manager returns a token to your requests that access the resource set.
-- The token marks the state of the resource set resource at the time of
-- the request. Update tokens are not allowed when creating a resource set.
-- After creation, each subsequent update call to the resource set requires
-- the update token.
--
-- To make an unconditional change to the resource set, omit the token in
-- your update request. Without the token, Firewall Manager performs your
-- updates regardless of whether the resource set has changed since you
-- last retrieved it.
--
-- To make a conditional change to the resource set, provide the token in
-- your update request. Firewall Manager uses the token to ensure that the
-- resource set hasn\'t changed since you last retrieved it. If it has
-- changed, the operation fails with an @InvalidTokenException@. If this
-- happens, retrieve the resource set again to get a current copy of it
-- with a new token. Reapply your changes as needed, then try the operation
-- again using the new token.
--
-- 'name', 'resourceSet_name' - The descriptive name of the resource set. You can\'t change the name of
-- a resource set after you create it.
--
-- 'resourceTypeList', 'resourceSet_resourceTypeList' - Determines the resources that can be associated to the resource set.
-- Depending on your setting for max results and the number of resource
-- sets, a single call might not return the full list.
newResourceSet ::
  -- | 'name'
  Prelude.Text ->
  ResourceSet
newResourceSet :: Text -> ResourceSet
newResourceSet Text
pName_ =
  ResourceSet'
    { $sel:description:ResourceSet' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:id:ResourceSet' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdateTime:ResourceSet' :: Maybe POSIX
lastUpdateTime = forall a. Maybe a
Prelude.Nothing,
      $sel:updateToken:ResourceSet' :: Maybe Text
updateToken = forall a. Maybe a
Prelude.Nothing,
      $sel:name:ResourceSet' :: Text
name = Text
pName_,
      $sel:resourceTypeList:ResourceSet' :: [Text]
resourceTypeList = forall a. Monoid a => a
Prelude.mempty
    }

-- | A description of the resource set.
resourceSet_description :: Lens.Lens' ResourceSet (Prelude.Maybe Prelude.Text)
resourceSet_description :: Lens' ResourceSet (Maybe Text)
resourceSet_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {Maybe Text
description :: Maybe Text
$sel:description:ResourceSet' :: ResourceSet -> Maybe Text
description} -> Maybe Text
description) (\s :: ResourceSet
s@ResourceSet' {} Maybe Text
a -> ResourceSet
s {$sel:description:ResourceSet' :: Maybe Text
description = Maybe Text
a} :: ResourceSet)

-- | A unique identifier for the resource set. This ID is returned in the
-- responses to create and list commands. You provide it to operations like
-- update and delete.
resourceSet_id :: Lens.Lens' ResourceSet (Prelude.Maybe Prelude.Text)
resourceSet_id :: Lens' ResourceSet (Maybe Text)
resourceSet_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {Maybe Text
id :: Maybe Text
$sel:id:ResourceSet' :: ResourceSet -> Maybe Text
id} -> Maybe Text
id) (\s :: ResourceSet
s@ResourceSet' {} Maybe Text
a -> ResourceSet
s {$sel:id:ResourceSet' :: Maybe Text
id = Maybe Text
a} :: ResourceSet)

-- | The last time that the resource set was changed.
resourceSet_lastUpdateTime :: Lens.Lens' ResourceSet (Prelude.Maybe Prelude.UTCTime)
resourceSet_lastUpdateTime :: Lens' ResourceSet (Maybe UTCTime)
resourceSet_lastUpdateTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {Maybe POSIX
lastUpdateTime :: Maybe POSIX
$sel:lastUpdateTime:ResourceSet' :: ResourceSet -> Maybe POSIX
lastUpdateTime} -> Maybe POSIX
lastUpdateTime) (\s :: ResourceSet
s@ResourceSet' {} Maybe POSIX
a -> ResourceSet
s {$sel:lastUpdateTime:ResourceSet' :: Maybe POSIX
lastUpdateTime = Maybe POSIX
a} :: ResourceSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | An optional token that you can use for optimistic locking. Firewall
-- Manager returns a token to your requests that access the resource set.
-- The token marks the state of the resource set resource at the time of
-- the request. Update tokens are not allowed when creating a resource set.
-- After creation, each subsequent update call to the resource set requires
-- the update token.
--
-- To make an unconditional change to the resource set, omit the token in
-- your update request. Without the token, Firewall Manager performs your
-- updates regardless of whether the resource set has changed since you
-- last retrieved it.
--
-- To make a conditional change to the resource set, provide the token in
-- your update request. Firewall Manager uses the token to ensure that the
-- resource set hasn\'t changed since you last retrieved it. If it has
-- changed, the operation fails with an @InvalidTokenException@. If this
-- happens, retrieve the resource set again to get a current copy of it
-- with a new token. Reapply your changes as needed, then try the operation
-- again using the new token.
resourceSet_updateToken :: Lens.Lens' ResourceSet (Prelude.Maybe Prelude.Text)
resourceSet_updateToken :: Lens' ResourceSet (Maybe Text)
resourceSet_updateToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {Maybe Text
updateToken :: Maybe Text
$sel:updateToken:ResourceSet' :: ResourceSet -> Maybe Text
updateToken} -> Maybe Text
updateToken) (\s :: ResourceSet
s@ResourceSet' {} Maybe Text
a -> ResourceSet
s {$sel:updateToken:ResourceSet' :: Maybe Text
updateToken = Maybe Text
a} :: ResourceSet)

-- | The descriptive name of the resource set. You can\'t change the name of
-- a resource set after you create it.
resourceSet_name :: Lens.Lens' ResourceSet Prelude.Text
resourceSet_name :: Lens' ResourceSet Text
resourceSet_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {Text
name :: Text
$sel:name:ResourceSet' :: ResourceSet -> Text
name} -> Text
name) (\s :: ResourceSet
s@ResourceSet' {} Text
a -> ResourceSet
s {$sel:name:ResourceSet' :: Text
name = Text
a} :: ResourceSet)

-- | Determines the resources that can be associated to the resource set.
-- Depending on your setting for max results and the number of resource
-- sets, a single call might not return the full list.
resourceSet_resourceTypeList :: Lens.Lens' ResourceSet [Prelude.Text]
resourceSet_resourceTypeList :: Lens' ResourceSet [Text]
resourceSet_resourceTypeList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceSet' {[Text]
resourceTypeList :: [Text]
$sel:resourceTypeList:ResourceSet' :: ResourceSet -> [Text]
resourceTypeList} -> [Text]
resourceTypeList) (\s :: ResourceSet
s@ResourceSet' {} [Text]
a -> ResourceSet
s {$sel:resourceTypeList:ResourceSet' :: [Text]
resourceTypeList = [Text]
a} :: ResourceSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON ResourceSet where
  parseJSON :: Value -> Parser ResourceSet
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourceSet"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Text
-> [Text]
-> ResourceSet
ResourceSet'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Id")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LastUpdateTime")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"UpdateToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ResourceTypeList"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable ResourceSet where
  hashWithSalt :: Int -> ResourceSet -> Int
hashWithSalt Int
_salt ResourceSet' {[Text]
Maybe Text
Maybe POSIX
Text
resourceTypeList :: [Text]
name :: Text
updateToken :: Maybe Text
lastUpdateTime :: Maybe POSIX
id :: Maybe Text
description :: Maybe Text
$sel:resourceTypeList:ResourceSet' :: ResourceSet -> [Text]
$sel:name:ResourceSet' :: ResourceSet -> Text
$sel:updateToken:ResourceSet' :: ResourceSet -> Maybe Text
$sel:lastUpdateTime:ResourceSet' :: ResourceSet -> Maybe POSIX
$sel:id:ResourceSet' :: ResourceSet -> Maybe Text
$sel:description:ResourceSet' :: ResourceSet -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastUpdateTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
updateToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
resourceTypeList

instance Prelude.NFData ResourceSet where
  rnf :: ResourceSet -> ()
rnf ResourceSet' {[Text]
Maybe Text
Maybe POSIX
Text
resourceTypeList :: [Text]
name :: Text
updateToken :: Maybe Text
lastUpdateTime :: Maybe POSIX
id :: Maybe Text
description :: Maybe Text
$sel:resourceTypeList:ResourceSet' :: ResourceSet -> [Text]
$sel:name:ResourceSet' :: ResourceSet -> Text
$sel:updateToken:ResourceSet' :: ResourceSet -> Maybe Text
$sel:lastUpdateTime:ResourceSet' :: ResourceSet -> Maybe POSIX
$sel:id:ResourceSet' :: ResourceSet -> Maybe Text
$sel:description:ResourceSet' :: ResourceSet -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastUpdateTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
updateToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
resourceTypeList

instance Data.ToJSON ResourceSet where
  toJSON :: ResourceSet -> Value
toJSON ResourceSet' {[Text]
Maybe Text
Maybe POSIX
Text
resourceTypeList :: [Text]
name :: Text
updateToken :: Maybe Text
lastUpdateTime :: Maybe POSIX
id :: Maybe Text
description :: Maybe Text
$sel:resourceTypeList:ResourceSet' :: ResourceSet -> [Text]
$sel:name:ResourceSet' :: ResourceSet -> Text
$sel:updateToken:ResourceSet' :: ResourceSet -> Maybe Text
$sel:lastUpdateTime:ResourceSet' :: ResourceSet -> Maybe POSIX
$sel:id:ResourceSet' :: ResourceSet -> Maybe Text
$sel:description:ResourceSet' :: ResourceSet -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
id,
            (Key
"LastUpdateTime" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
lastUpdateTime,
            (Key
"UpdateToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
updateToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ResourceTypeList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
resourceTypeList)
          ]
      )