{-# 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.CloudWatchEvents.Types.Condition
-- 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.CloudWatchEvents.Types.Condition where

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

-- | A JSON string which you can use to limit the event bus permissions you
-- are granting to only accounts that fulfill the condition. Currently, the
-- only supported condition is membership in a certain Amazon Web Services
-- organization. The string must contain @Type@, @Key@, and @Value@ fields.
-- The @Value@ field specifies the ID of the Amazon Web Services
-- organization. Following is an example value for @Condition@:
--
-- @\'{\"Type\" : \"StringEquals\", \"Key\": \"aws:PrincipalOrgID\", \"Value\": \"o-1234567890\"}\'@
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | Specifies the type of condition. Currently the only supported value is
    -- @StringEquals@.
    Condition -> Text
type' :: Prelude.Text,
    -- | Specifies the key for the condition. Currently the only supported key is
    -- @aws:PrincipalOrgID@.
    Condition -> Text
key :: Prelude.Text,
    -- | Specifies the value for the key. Currently, this must be the ID of the
    -- organization.
    Condition -> Text
value :: Prelude.Text
  }
  deriving (Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c== :: Condition -> Condition -> Bool
Prelude.Eq, ReadPrec [Condition]
ReadPrec Condition
Int -> ReadS Condition
ReadS [Condition]
(Int -> ReadS Condition)
-> ReadS [Condition]
-> ReadPrec Condition
-> ReadPrec [Condition]
-> Read Condition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Condition]
$creadListPrec :: ReadPrec [Condition]
readPrec :: ReadPrec Condition
$creadPrec :: ReadPrec Condition
readList :: ReadS [Condition]
$creadList :: ReadS [Condition]
readsPrec :: Int -> ReadS Condition
$creadsPrec :: Int -> ReadS Condition
Prelude.Read, Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Condition] -> ShowS
$cshowList :: [Condition] -> ShowS
show :: Condition -> String
$cshow :: Condition -> String
showsPrec :: Int -> Condition -> ShowS
$cshowsPrec :: Int -> Condition -> ShowS
Prelude.Show, (forall x. Condition -> Rep Condition x)
-> (forall x. Rep Condition x -> Condition) -> Generic Condition
forall x. Rep Condition x -> Condition
forall x. Condition -> Rep Condition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Condition x -> Condition
$cfrom :: forall x. Condition -> Rep Condition x
Prelude.Generic)

-- |
-- Create a value of 'Condition' 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:
--
-- 'type'', 'condition_type' - Specifies the type of condition. Currently the only supported value is
-- @StringEquals@.
--
-- 'key', 'condition_key' - Specifies the key for the condition. Currently the only supported key is
-- @aws:PrincipalOrgID@.
--
-- 'value', 'condition_value' - Specifies the value for the key. Currently, this must be the ID of the
-- organization.
newCondition ::
  -- | 'type''
  Prelude.Text ->
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Condition
newCondition :: Text -> Text -> Text -> Condition
newCondition Text
pType_ Text
pKey_ Text
pValue_ =
  Condition' :: Text -> Text -> Text -> Condition
Condition'
    { $sel:type':Condition' :: Text
type' = Text
pType_,
      $sel:key:Condition' :: Text
key = Text
pKey_,
      $sel:value:Condition' :: Text
value = Text
pValue_
    }

-- | Specifies the type of condition. Currently the only supported value is
-- @StringEquals@.
condition_type :: Lens.Lens' Condition Prelude.Text
condition_type :: (Text -> f Text) -> Condition -> f Condition
condition_type = (Condition -> Text)
-> (Condition -> Text -> Condition)
-> Lens Condition Condition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Text
type' :: Text
$sel:type':Condition' :: Condition -> Text
type'} -> Text
type') (\s :: Condition
s@Condition' {} Text
a -> Condition
s {$sel:type':Condition' :: Text
type' = Text
a} :: Condition)

-- | Specifies the key for the condition. Currently the only supported key is
-- @aws:PrincipalOrgID@.
condition_key :: Lens.Lens' Condition Prelude.Text
condition_key :: (Text -> f Text) -> Condition -> f Condition
condition_key = (Condition -> Text)
-> (Condition -> Text -> Condition)
-> Lens Condition Condition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Text
key :: Text
$sel:key:Condition' :: Condition -> Text
key} -> Text
key) (\s :: Condition
s@Condition' {} Text
a -> Condition
s {$sel:key:Condition' :: Text
key = Text
a} :: Condition)

-- | Specifies the value for the key. Currently, this must be the ID of the
-- organization.
condition_value :: Lens.Lens' Condition Prelude.Text
condition_value :: (Text -> f Text) -> Condition -> f Condition
condition_value = (Condition -> Text)
-> (Condition -> Text -> Condition)
-> Lens Condition Condition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Text
value :: Text
$sel:value:Condition' :: Condition -> Text
value} -> Text
value) (\s :: Condition
s@Condition' {} Text
a -> Condition
s {$sel:value:Condition' :: Text
value = Text
a} :: Condition)

instance Prelude.Hashable Condition

instance Prelude.NFData Condition

instance Core.ToJSON Condition where
  toJSON :: Condition -> Value
toJSON Condition' {Text
value :: Text
key :: Text
type' :: Text
$sel:value:Condition' :: Condition -> Text
$sel:key:Condition' :: Condition -> Text
$sel:type':Condition' :: Condition -> 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
"Type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )