{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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. Used to filter resources using
-- their tags and assign them to a backup plan. Case sensitive.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | An operation applied to a key-value pair used to assign resources to
    -- your backup plan. Condition only supports @StringEquals@. For more
    -- flexible assignment options, including @StringLike@ and the ability to
    -- exclude resources from your backup plan, use @Conditions@ (with an \"s\"
    -- on the end) for your
    -- <https://docs.aws.amazon.com/aws-backup/latest/devguide/API_BackupSelection.html BackupSelection>
    -- .
    Condition -> ConditionType
conditionType :: ConditionType,
    -- | The key in a key-value pair. For example, in the tag
    -- @Department: Accounting@, @Department@ is the key.
    Condition -> Text
conditionKey :: Prelude.Text,
    -- | The value in a key-value pair. For example, in the tag
    -- @Department: Accounting@, @Accounting@ is the value.
    Condition -> Text
conditionValue :: 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:
--
-- 'conditionType', 'condition_conditionType' - An operation applied to a key-value pair used to assign resources to
-- your backup plan. Condition only supports @StringEquals@. For more
-- flexible assignment options, including @StringLike@ and the ability to
-- exclude resources from your backup plan, use @Conditions@ (with an \"s\"
-- on the end) for your
-- <https://docs.aws.amazon.com/aws-backup/latest/devguide/API_BackupSelection.html BackupSelection>
-- .
--
-- 'conditionKey', 'condition_conditionKey' - The key in a key-value pair. For example, in the tag
-- @Department: Accounting@, @Department@ is the key.
--
-- 'conditionValue', 'condition_conditionValue' - The value in a key-value pair. For example, in the tag
-- @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'
      { $sel:conditionType:Condition' :: ConditionType
conditionType = ConditionType
pConditionType_,
        $sel:conditionKey:Condition' :: Text
conditionKey = Text
pConditionKey_,
        $sel:conditionValue:Condition' :: Text
conditionValue = Text
pConditionValue_
      }

-- | An operation applied to a key-value pair used to assign resources to
-- your backup plan. Condition only supports @StringEquals@. For more
-- flexible assignment options, including @StringLike@ and the ability to
-- exclude resources from your backup plan, use @Conditions@ (with an \"s\"
-- on the end) for your
-- <https://docs.aws.amazon.com/aws-backup/latest/devguide/API_BackupSelection.html BackupSelection>
-- .
condition_conditionType :: Lens.Lens' Condition ConditionType
condition_conditionType :: Lens' Condition ConditionType
condition_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 the tag
-- @Department: Accounting@, @Department@ is the key.
condition_conditionKey :: Lens.Lens' Condition Prelude.Text
condition_conditionKey :: Lens' Condition Text
condition_conditionKey = 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 the tag
-- @Department: Accounting@, @Accounting@ is the value.
condition_conditionValue :: Lens.Lens' Condition Prelude.Text
condition_conditionValue :: Lens' Condition Text
condition_conditionValue = 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 Data.FromJSON Condition where
  parseJSON :: Value -> Parser Condition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Condition"
      ( \Object
x ->
          ConditionType -> Text -> Text -> Condition
Condition'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ConditionType")
            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
"ConditionKey")
            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
"ConditionValue")
      )

instance Prelude.Hashable Condition where
  hashWithSalt :: Int -> Condition -> Int
hashWithSalt Int
_salt Condition' {Text
ConditionType
conditionValue :: Text
conditionKey :: Text
conditionType :: ConditionType
$sel:conditionValue:Condition' :: Condition -> Text
$sel:conditionKey:Condition' :: Condition -> Text
$sel:conditionType:Condition' :: Condition -> ConditionType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ConditionType
conditionType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
conditionKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
conditionValue

instance Prelude.NFData Condition where
  rnf :: Condition -> ()
rnf Condition' {Text
ConditionType
conditionValue :: Text
conditionKey :: Text
conditionType :: ConditionType
$sel:conditionValue:Condition' :: Condition -> Text
$sel:conditionKey:Condition' :: Condition -> Text
$sel:conditionType:Condition' :: Condition -> ConditionType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ConditionType
conditionType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
conditionKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
conditionValue

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ConditionType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ConditionType
conditionType),
            forall a. a -> Maybe a
Prelude.Just (Key
"ConditionKey" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
conditionKey),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ConditionValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
conditionValue)
          ]
      )