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

import Amazonka.Backup.Types.ConditionType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an array of triplets made up of a condition type (such as
-- @StringEquals@), a key, and a value. Conditions are used to filter
-- resources in a selection that is assigned to a backup plan.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | An operation, such as @StringEquals@, that is applied to a key-value
    -- pair used to filter resources in a selection.
    Condition -> ConditionType
conditionType :: ConditionType,
    -- | The key in a key-value pair. For example, in
    -- @\"ec2:ResourceTag\/Department\": \"accounting\"@,
    -- @\"ec2:ResourceTag\/Department\"@ is the key.
    Condition -> Text
conditionKey :: Prelude.Text,
    -- | The value in a key-value pair. For example, in
    -- @\"ec2:ResourceTag\/Department\": \"accounting\"@, @\"accounting\"@ is
    -- the value.
    Condition -> Text
conditionValue :: 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:
--
-- 'conditionType', 'condition_conditionType' - An operation, such as @StringEquals@, that is applied to a key-value
-- pair used to filter resources in a selection.
--
-- 'conditionKey', 'condition_conditionKey' - The key in a key-value pair. For example, in
-- @\"ec2:ResourceTag\/Department\": \"accounting\"@,
-- @\"ec2:ResourceTag\/Department\"@ is the key.
--
-- 'conditionValue', 'condition_conditionValue' - The value in a key-value pair. For example, in
-- @\"ec2:ResourceTag\/Department\": \"accounting\"@, @\"accounting\"@ is
-- the value.
newCondition ::
  -- | 'conditionType'
  ConditionType ->
  -- | 'conditionKey'
  Prelude.Text ->
  -- | 'conditionValue'
  Prelude.Text ->
  Condition
newCondition :: ConditionType -> Text -> Text -> Condition
newCondition
  ConditionType
pConditionType_
  Text
pConditionKey_
  Text
pConditionValue_ =
    Condition' :: ConditionType -> Text -> Text -> Condition
Condition'
      { $sel:conditionType:Condition' :: ConditionType
conditionType = ConditionType
pConditionType_,
        $sel:conditionKey:Condition' :: Text
conditionKey = Text
pConditionKey_,
        $sel:conditionValue:Condition' :: Text
conditionValue = Text
pConditionValue_
      }

-- | An operation, such as @StringEquals@, that is applied to a key-value
-- pair used to filter resources in a selection.
condition_conditionType :: Lens.Lens' Condition ConditionType
condition_conditionType :: (ConditionType -> f ConditionType) -> Condition -> f Condition
condition_conditionType = (Condition -> ConditionType)
-> (Condition -> ConditionType -> Condition)
-> Lens Condition Condition ConditionType ConditionType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {ConditionType
conditionType :: ConditionType
$sel:conditionType:Condition' :: Condition -> ConditionType
conditionType} -> ConditionType
conditionType) (\s :: Condition
s@Condition' {} ConditionType
a -> Condition
s {$sel:conditionType:Condition' :: ConditionType
conditionType = ConditionType
a} :: Condition)

-- | The key in a key-value pair. For example, in
-- @\"ec2:ResourceTag\/Department\": \"accounting\"@,
-- @\"ec2:ResourceTag\/Department\"@ is the key.
condition_conditionKey :: Lens.Lens' Condition Prelude.Text
condition_conditionKey :: (Text -> f Text) -> Condition -> f Condition
condition_conditionKey = (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
conditionKey :: Text
$sel:conditionKey:Condition' :: Condition -> Text
conditionKey} -> Text
conditionKey) (\s :: Condition
s@Condition' {} Text
a -> Condition
s {$sel:conditionKey:Condition' :: Text
conditionKey = Text
a} :: Condition)

-- | The value in a key-value pair. For example, in
-- @\"ec2:ResourceTag\/Department\": \"accounting\"@, @\"accounting\"@ is
-- the value.
condition_conditionValue :: Lens.Lens' Condition Prelude.Text
condition_conditionValue :: (Text -> f Text) -> Condition -> f Condition
condition_conditionValue = (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
conditionValue :: Text
$sel:conditionValue:Condition' :: Condition -> Text
conditionValue} -> Text
conditionValue) (\s :: Condition
s@Condition' {} Text
a -> Condition
s {$sel:conditionValue:Condition' :: Text
conditionValue = Text
a} :: Condition)

instance Core.FromJSON Condition where
  parseJSON :: Value -> Parser Condition
parseJSON =
    String -> (Object -> Parser Condition) -> Value -> Parser Condition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Condition"
      ( \Object
x ->
          ConditionType -> Text -> Text -> Condition
Condition'
            (ConditionType -> Text -> Text -> Condition)
-> Parser ConditionType -> Parser (Text -> Text -> Condition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser ConditionType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConditionType")
            Parser (Text -> Text -> Condition)
-> Parser Text -> Parser (Text -> Condition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConditionKey")
            Parser (Text -> Condition) -> Parser Text -> Parser Condition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConditionValue")
      )

instance Prelude.Hashable Condition

instance Prelude.NFData Condition

instance Core.ToJSON Condition where
  toJSON :: Condition -> Value
toJSON Condition' {Text
ConditionType
conditionValue :: Text
conditionKey :: Text
conditionType :: ConditionType
$sel:conditionValue:Condition' :: Condition -> Text
$sel:conditionKey:Condition' :: Condition -> Text
$sel:conditionType:Condition' :: Condition -> ConditionType
..} =
    [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
"ConditionType" Text -> ConditionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConditionType
conditionType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ConditionKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
conditionKey),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ConditionValue" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
conditionValue)
          ]
      )