{-# 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.AmplifyUiBuilder.Types.ComponentConditionProperty
-- 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.AmplifyUiBuilder.Types.ComponentConditionProperty where

import {-# SOURCE #-} Amazonka.AmplifyUiBuilder.Types.ComponentProperty
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

-- | Represents a conditional expression to set a component property. Use
-- @ComponentConditionProperty@ to set a property to different values
-- conditionally, based on the value of another property.
--
-- /See:/ 'newComponentConditionProperty' smart constructor.
data ComponentConditionProperty = ComponentConditionProperty'
  { -- | The value to assign to the property if the condition is not met.
    ComponentConditionProperty -> Maybe ComponentProperty
else' :: Prelude.Maybe ComponentProperty,
    -- | The name of a field. Specify this when the property is a data model.
    ComponentConditionProperty -> Maybe Text
field :: Prelude.Maybe Prelude.Text,
    -- | The value of the property to evaluate.
    ComponentConditionProperty -> Maybe Text
operand :: Prelude.Maybe Prelude.Text,
    -- | The type of the property to evaluate.
    ComponentConditionProperty -> Maybe Text
operandType :: Prelude.Maybe Prelude.Text,
    -- | The operator to use to perform the evaluation, such as @eq@ to represent
    -- equals.
    ComponentConditionProperty -> Maybe Text
operator :: Prelude.Maybe Prelude.Text,
    -- | The name of the conditional property.
    ComponentConditionProperty -> Maybe Text
property :: Prelude.Maybe Prelude.Text,
    -- | The value to assign to the property if the condition is met.
    ComponentConditionProperty -> Maybe ComponentProperty
then' :: Prelude.Maybe ComponentProperty
  }
  deriving (ComponentConditionProperty -> ComponentConditionProperty -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ComponentConditionProperty -> ComponentConditionProperty -> Bool
$c/= :: ComponentConditionProperty -> ComponentConditionProperty -> Bool
== :: ComponentConditionProperty -> ComponentConditionProperty -> Bool
$c== :: ComponentConditionProperty -> ComponentConditionProperty -> Bool
Prelude.Eq, ReadPrec [ComponentConditionProperty]
ReadPrec ComponentConditionProperty
Int -> ReadS ComponentConditionProperty
ReadS [ComponentConditionProperty]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ComponentConditionProperty]
$creadListPrec :: ReadPrec [ComponentConditionProperty]
readPrec :: ReadPrec ComponentConditionProperty
$creadPrec :: ReadPrec ComponentConditionProperty
readList :: ReadS [ComponentConditionProperty]
$creadList :: ReadS [ComponentConditionProperty]
readsPrec :: Int -> ReadS ComponentConditionProperty
$creadsPrec :: Int -> ReadS ComponentConditionProperty
Prelude.Read, Int -> ComponentConditionProperty -> ShowS
[ComponentConditionProperty] -> ShowS
ComponentConditionProperty -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ComponentConditionProperty] -> ShowS
$cshowList :: [ComponentConditionProperty] -> ShowS
show :: ComponentConditionProperty -> String
$cshow :: ComponentConditionProperty -> String
showsPrec :: Int -> ComponentConditionProperty -> ShowS
$cshowsPrec :: Int -> ComponentConditionProperty -> ShowS
Prelude.Show, forall x.
Rep ComponentConditionProperty x -> ComponentConditionProperty
forall x.
ComponentConditionProperty -> Rep ComponentConditionProperty x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ComponentConditionProperty x -> ComponentConditionProperty
$cfrom :: forall x.
ComponentConditionProperty -> Rep ComponentConditionProperty x
Prelude.Generic)

-- |
-- Create a value of 'ComponentConditionProperty' 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:
--
-- 'else'', 'componentConditionProperty_else' - The value to assign to the property if the condition is not met.
--
-- 'field', 'componentConditionProperty_field' - The name of a field. Specify this when the property is a data model.
--
-- 'operand', 'componentConditionProperty_operand' - The value of the property to evaluate.
--
-- 'operandType', 'componentConditionProperty_operandType' - The type of the property to evaluate.
--
-- 'operator', 'componentConditionProperty_operator' - The operator to use to perform the evaluation, such as @eq@ to represent
-- equals.
--
-- 'property', 'componentConditionProperty_property' - The name of the conditional property.
--
-- 'then'', 'componentConditionProperty_then' - The value to assign to the property if the condition is met.
newComponentConditionProperty ::
  ComponentConditionProperty
newComponentConditionProperty :: ComponentConditionProperty
newComponentConditionProperty =
  ComponentConditionProperty'
    { $sel:else':ComponentConditionProperty' :: Maybe ComponentProperty
else' =
        forall a. Maybe a
Prelude.Nothing,
      $sel:field:ComponentConditionProperty' :: Maybe Text
field = forall a. Maybe a
Prelude.Nothing,
      $sel:operand:ComponentConditionProperty' :: Maybe Text
operand = forall a. Maybe a
Prelude.Nothing,
      $sel:operandType:ComponentConditionProperty' :: Maybe Text
operandType = forall a. Maybe a
Prelude.Nothing,
      $sel:operator:ComponentConditionProperty' :: Maybe Text
operator = forall a. Maybe a
Prelude.Nothing,
      $sel:property:ComponentConditionProperty' :: Maybe Text
property = forall a. Maybe a
Prelude.Nothing,
      $sel:then':ComponentConditionProperty' :: Maybe ComponentProperty
then' = forall a. Maybe a
Prelude.Nothing
    }

-- | The value to assign to the property if the condition is not met.
componentConditionProperty_else :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe ComponentProperty)
componentConditionProperty_else :: Lens' ComponentConditionProperty (Maybe ComponentProperty)
componentConditionProperty_else = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe ComponentProperty
else' :: Maybe ComponentProperty
$sel:else':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
else'} -> Maybe ComponentProperty
else') (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe ComponentProperty
a -> ComponentConditionProperty
s {$sel:else':ComponentConditionProperty' :: Maybe ComponentProperty
else' = Maybe ComponentProperty
a} :: ComponentConditionProperty)

-- | The name of a field. Specify this when the property is a data model.
componentConditionProperty_field :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe Prelude.Text)
componentConditionProperty_field :: Lens' ComponentConditionProperty (Maybe Text)
componentConditionProperty_field = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe Text
field :: Maybe Text
$sel:field:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
field} -> Maybe Text
field) (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe Text
a -> ComponentConditionProperty
s {$sel:field:ComponentConditionProperty' :: Maybe Text
field = Maybe Text
a} :: ComponentConditionProperty)

-- | The value of the property to evaluate.
componentConditionProperty_operand :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe Prelude.Text)
componentConditionProperty_operand :: Lens' ComponentConditionProperty (Maybe Text)
componentConditionProperty_operand = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe Text
operand :: Maybe Text
$sel:operand:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
operand} -> Maybe Text
operand) (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe Text
a -> ComponentConditionProperty
s {$sel:operand:ComponentConditionProperty' :: Maybe Text
operand = Maybe Text
a} :: ComponentConditionProperty)

-- | The type of the property to evaluate.
componentConditionProperty_operandType :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe Prelude.Text)
componentConditionProperty_operandType :: Lens' ComponentConditionProperty (Maybe Text)
componentConditionProperty_operandType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe Text
operandType :: Maybe Text
$sel:operandType:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
operandType} -> Maybe Text
operandType) (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe Text
a -> ComponentConditionProperty
s {$sel:operandType:ComponentConditionProperty' :: Maybe Text
operandType = Maybe Text
a} :: ComponentConditionProperty)

-- | The operator to use to perform the evaluation, such as @eq@ to represent
-- equals.
componentConditionProperty_operator :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe Prelude.Text)
componentConditionProperty_operator :: Lens' ComponentConditionProperty (Maybe Text)
componentConditionProperty_operator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe Text
operator :: Maybe Text
$sel:operator:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
operator} -> Maybe Text
operator) (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe Text
a -> ComponentConditionProperty
s {$sel:operator:ComponentConditionProperty' :: Maybe Text
operator = Maybe Text
a} :: ComponentConditionProperty)

-- | The name of the conditional property.
componentConditionProperty_property :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe Prelude.Text)
componentConditionProperty_property :: Lens' ComponentConditionProperty (Maybe Text)
componentConditionProperty_property = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe Text
property :: Maybe Text
$sel:property:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
property} -> Maybe Text
property) (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe Text
a -> ComponentConditionProperty
s {$sel:property:ComponentConditionProperty' :: Maybe Text
property = Maybe Text
a} :: ComponentConditionProperty)

-- | The value to assign to the property if the condition is met.
componentConditionProperty_then :: Lens.Lens' ComponentConditionProperty (Prelude.Maybe ComponentProperty)
componentConditionProperty_then :: Lens' ComponentConditionProperty (Maybe ComponentProperty)
componentConditionProperty_then = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ComponentConditionProperty' {Maybe ComponentProperty
then' :: Maybe ComponentProperty
$sel:then':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
then'} -> Maybe ComponentProperty
then') (\s :: ComponentConditionProperty
s@ComponentConditionProperty' {} Maybe ComponentProperty
a -> ComponentConditionProperty
s {$sel:then':ComponentConditionProperty' :: Maybe ComponentProperty
then' = Maybe ComponentProperty
a} :: ComponentConditionProperty)

instance Data.FromJSON ComponentConditionProperty where
  parseJSON :: Value -> Parser ComponentConditionProperty
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ComponentConditionProperty"
      ( \Object
x ->
          Maybe ComponentProperty
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe ComponentProperty
-> ComponentConditionProperty
ComponentConditionProperty'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"else")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"field")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"operand")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"operandType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"operator")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"property")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"then")
      )

instance Prelude.Hashable ComponentConditionProperty where
  hashWithSalt :: Int -> ComponentConditionProperty -> Int
hashWithSalt Int
_salt ComponentConditionProperty' {Maybe Text
Maybe ComponentProperty
then' :: Maybe ComponentProperty
property :: Maybe Text
operator :: Maybe Text
operandType :: Maybe Text
operand :: Maybe Text
field :: Maybe Text
else' :: Maybe ComponentProperty
$sel:then':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
$sel:property:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operator:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operandType:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operand:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:field:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:else':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ComponentProperty
else'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
field
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
operand
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
operandType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
operator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
property
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ComponentProperty
then'

instance Prelude.NFData ComponentConditionProperty where
  rnf :: ComponentConditionProperty -> ()
rnf ComponentConditionProperty' {Maybe Text
Maybe ComponentProperty
then' :: Maybe ComponentProperty
property :: Maybe Text
operator :: Maybe Text
operandType :: Maybe Text
operand :: Maybe Text
field :: Maybe Text
else' :: Maybe ComponentProperty
$sel:then':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
$sel:property:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operator:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operandType:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operand:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:field:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:else':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ComponentProperty
else'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
field
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
operand
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
operandType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
operator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
property
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ComponentProperty
then'

instance Data.ToJSON ComponentConditionProperty where
  toJSON :: ComponentConditionProperty -> Value
toJSON ComponentConditionProperty' {Maybe Text
Maybe ComponentProperty
then' :: Maybe ComponentProperty
property :: Maybe Text
operator :: Maybe Text
operandType :: Maybe Text
operand :: Maybe Text
field :: Maybe Text
else' :: Maybe ComponentProperty
$sel:then':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
$sel:property:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operator:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operandType:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:operand:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:field:ComponentConditionProperty' :: ComponentConditionProperty -> Maybe Text
$sel:else':ComponentConditionProperty' :: ComponentConditionProperty -> Maybe ComponentProperty
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"else" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ComponentProperty
else',
            (Key
"field" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
field,
            (Key
"operand" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
operand,
            (Key
"operandType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
operandType,
            (Key
"operator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
operator,
            (Key
"property" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
property,
            (Key
"then" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ComponentProperty
then'
          ]
      )