{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchEvents.Types.Condition 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 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
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]
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
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. 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'
    { $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 :: Lens' Condition Text
condition_type = 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 :: Lens' Condition Text
condition_key = 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 :: Lens' Condition Text
condition_value = 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 where
  hashWithSalt :: Int -> Condition -> Int
hashWithSalt Int
_salt Condition' {Text
value :: Text
key :: Text
type' :: Text
$sel:value:Condition' :: Condition -> Text
$sel:key:Condition' :: Condition -> Text
$sel:type':Condition' :: Condition -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

instance Prelude.NFData Condition where
  rnf :: Condition -> ()
rnf Condition' {Text
value :: Text
key :: Text
type' :: Text
$sel:value:Condition' :: Condition -> Text
$sel:key:Condition' :: Condition -> Text
$sel:type':Condition' :: Condition -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
value

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value)
          ]
      )