{-# 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.ManagedBlockChain.Types.ProposalActions
-- 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.ManagedBlockChain.Types.ProposalActions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.ManagedBlockChain.Types.InviteAction
import Amazonka.ManagedBlockChain.Types.RemoveAction
import qualified Amazonka.Prelude as Prelude

-- | The actions to carry out if a proposal is @APPROVED@.
--
-- Applies only to Hyperledger Fabric.
--
-- /See:/ 'newProposalActions' smart constructor.
data ProposalActions = ProposalActions'
  { -- | The actions to perform for an @APPROVED@ proposal to invite an AWS
    -- account to create a member and join the network.
    ProposalActions -> Maybe [InviteAction]
invitations :: Prelude.Maybe [InviteAction],
    -- | The actions to perform for an @APPROVED@ proposal to remove a member
    -- from the network, which deletes the member and all associated member
    -- resources from the network.
    ProposalActions -> Maybe [RemoveAction]
removals :: Prelude.Maybe [RemoveAction]
  }
  deriving (ProposalActions -> ProposalActions -> Bool
(ProposalActions -> ProposalActions -> Bool)
-> (ProposalActions -> ProposalActions -> Bool)
-> Eq ProposalActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProposalActions -> ProposalActions -> Bool
$c/= :: ProposalActions -> ProposalActions -> Bool
== :: ProposalActions -> ProposalActions -> Bool
$c== :: ProposalActions -> ProposalActions -> Bool
Prelude.Eq, ReadPrec [ProposalActions]
ReadPrec ProposalActions
Int -> ReadS ProposalActions
ReadS [ProposalActions]
(Int -> ReadS ProposalActions)
-> ReadS [ProposalActions]
-> ReadPrec ProposalActions
-> ReadPrec [ProposalActions]
-> Read ProposalActions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProposalActions]
$creadListPrec :: ReadPrec [ProposalActions]
readPrec :: ReadPrec ProposalActions
$creadPrec :: ReadPrec ProposalActions
readList :: ReadS [ProposalActions]
$creadList :: ReadS [ProposalActions]
readsPrec :: Int -> ReadS ProposalActions
$creadsPrec :: Int -> ReadS ProposalActions
Prelude.Read, Int -> ProposalActions -> ShowS
[ProposalActions] -> ShowS
ProposalActions -> String
(Int -> ProposalActions -> ShowS)
-> (ProposalActions -> String)
-> ([ProposalActions] -> ShowS)
-> Show ProposalActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProposalActions] -> ShowS
$cshowList :: [ProposalActions] -> ShowS
show :: ProposalActions -> String
$cshow :: ProposalActions -> String
showsPrec :: Int -> ProposalActions -> ShowS
$cshowsPrec :: Int -> ProposalActions -> ShowS
Prelude.Show, (forall x. ProposalActions -> Rep ProposalActions x)
-> (forall x. Rep ProposalActions x -> ProposalActions)
-> Generic ProposalActions
forall x. Rep ProposalActions x -> ProposalActions
forall x. ProposalActions -> Rep ProposalActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProposalActions x -> ProposalActions
$cfrom :: forall x. ProposalActions -> Rep ProposalActions x
Prelude.Generic)

-- |
-- Create a value of 'ProposalActions' 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:
--
-- 'invitations', 'proposalActions_invitations' - The actions to perform for an @APPROVED@ proposal to invite an AWS
-- account to create a member and join the network.
--
-- 'removals', 'proposalActions_removals' - The actions to perform for an @APPROVED@ proposal to remove a member
-- from the network, which deletes the member and all associated member
-- resources from the network.
newProposalActions ::
  ProposalActions
newProposalActions :: ProposalActions
newProposalActions =
  ProposalActions' :: Maybe [InviteAction] -> Maybe [RemoveAction] -> ProposalActions
ProposalActions'
    { $sel:invitations:ProposalActions' :: Maybe [InviteAction]
invitations = Maybe [InviteAction]
forall a. Maybe a
Prelude.Nothing,
      $sel:removals:ProposalActions' :: Maybe [RemoveAction]
removals = Maybe [RemoveAction]
forall a. Maybe a
Prelude.Nothing
    }

-- | The actions to perform for an @APPROVED@ proposal to invite an AWS
-- account to create a member and join the network.
proposalActions_invitations :: Lens.Lens' ProposalActions (Prelude.Maybe [InviteAction])
proposalActions_invitations :: (Maybe [InviteAction] -> f (Maybe [InviteAction]))
-> ProposalActions -> f ProposalActions
proposalActions_invitations = (ProposalActions -> Maybe [InviteAction])
-> (ProposalActions -> Maybe [InviteAction] -> ProposalActions)
-> Lens
     ProposalActions
     ProposalActions
     (Maybe [InviteAction])
     (Maybe [InviteAction])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProposalActions' {Maybe [InviteAction]
invitations :: Maybe [InviteAction]
$sel:invitations:ProposalActions' :: ProposalActions -> Maybe [InviteAction]
invitations} -> Maybe [InviteAction]
invitations) (\s :: ProposalActions
s@ProposalActions' {} Maybe [InviteAction]
a -> ProposalActions
s {$sel:invitations:ProposalActions' :: Maybe [InviteAction]
invitations = Maybe [InviteAction]
a} :: ProposalActions) ((Maybe [InviteAction] -> f (Maybe [InviteAction]))
 -> ProposalActions -> f ProposalActions)
-> ((Maybe [InviteAction] -> f (Maybe [InviteAction]))
    -> Maybe [InviteAction] -> f (Maybe [InviteAction]))
-> (Maybe [InviteAction] -> f (Maybe [InviteAction]))
-> ProposalActions
-> f ProposalActions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [InviteAction] [InviteAction] [InviteAction] [InviteAction]
-> Iso
     (Maybe [InviteAction])
     (Maybe [InviteAction])
     (Maybe [InviteAction])
     (Maybe [InviteAction])
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 [InviteAction] [InviteAction] [InviteAction] [InviteAction]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The actions to perform for an @APPROVED@ proposal to remove a member
-- from the network, which deletes the member and all associated member
-- resources from the network.
proposalActions_removals :: Lens.Lens' ProposalActions (Prelude.Maybe [RemoveAction])
proposalActions_removals :: (Maybe [RemoveAction] -> f (Maybe [RemoveAction]))
-> ProposalActions -> f ProposalActions
proposalActions_removals = (ProposalActions -> Maybe [RemoveAction])
-> (ProposalActions -> Maybe [RemoveAction] -> ProposalActions)
-> Lens
     ProposalActions
     ProposalActions
     (Maybe [RemoveAction])
     (Maybe [RemoveAction])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProposalActions' {Maybe [RemoveAction]
removals :: Maybe [RemoveAction]
$sel:removals:ProposalActions' :: ProposalActions -> Maybe [RemoveAction]
removals} -> Maybe [RemoveAction]
removals) (\s :: ProposalActions
s@ProposalActions' {} Maybe [RemoveAction]
a -> ProposalActions
s {$sel:removals:ProposalActions' :: Maybe [RemoveAction]
removals = Maybe [RemoveAction]
a} :: ProposalActions) ((Maybe [RemoveAction] -> f (Maybe [RemoveAction]))
 -> ProposalActions -> f ProposalActions)
-> ((Maybe [RemoveAction] -> f (Maybe [RemoveAction]))
    -> Maybe [RemoveAction] -> f (Maybe [RemoveAction]))
-> (Maybe [RemoveAction] -> f (Maybe [RemoveAction]))
-> ProposalActions
-> f ProposalActions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [RemoveAction] [RemoveAction] [RemoveAction] [RemoveAction]
-> Iso
     (Maybe [RemoveAction])
     (Maybe [RemoveAction])
     (Maybe [RemoveAction])
     (Maybe [RemoveAction])
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 [RemoveAction] [RemoveAction] [RemoveAction] [RemoveAction]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ProposalActions where
  parseJSON :: Value -> Parser ProposalActions
parseJSON =
    String
-> (Object -> Parser ProposalActions)
-> Value
-> Parser ProposalActions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProposalActions"
      ( \Object
x ->
          Maybe [InviteAction] -> Maybe [RemoveAction] -> ProposalActions
ProposalActions'
            (Maybe [InviteAction] -> Maybe [RemoveAction] -> ProposalActions)
-> Parser (Maybe [InviteAction])
-> Parser (Maybe [RemoveAction] -> ProposalActions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [InviteAction]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Invitations" Parser (Maybe (Maybe [InviteAction]))
-> Maybe [InviteAction] -> Parser (Maybe [InviteAction])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [InviteAction]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe [RemoveAction] -> ProposalActions)
-> Parser (Maybe [RemoveAction]) -> Parser ProposalActions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [RemoveAction]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Removals" Parser (Maybe (Maybe [RemoveAction]))
-> Maybe [RemoveAction] -> Parser (Maybe [RemoveAction])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [RemoveAction]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ProposalActions

instance Prelude.NFData ProposalActions

instance Core.ToJSON ProposalActions where
  toJSON :: ProposalActions -> Value
toJSON ProposalActions' {Maybe [InviteAction]
Maybe [RemoveAction]
removals :: Maybe [RemoveAction]
invitations :: Maybe [InviteAction]
$sel:removals:ProposalActions' :: ProposalActions -> Maybe [RemoveAction]
$sel:invitations:ProposalActions' :: ProposalActions -> Maybe [InviteAction]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Invitations" Text -> [InviteAction] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([InviteAction] -> Pair) -> Maybe [InviteAction] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [InviteAction]
invitations,
            (Text
"Removals" Text -> [RemoveAction] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([RemoveAction] -> Pair) -> Maybe [RemoveAction] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [RemoveAction]
removals
          ]
      )