{-# 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.LexModels.Types.SlotDefaultValueSpec
-- 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.LexModels.Types.SlotDefaultValueSpec where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LexModels.Types.SlotDefaultValue
import qualified Amazonka.Prelude as Prelude

-- | Contains the default values for a slot. Default values are used when
-- Amazon Lex hasn\'t determined a value for a slot.
--
-- /See:/ 'newSlotDefaultValueSpec' smart constructor.
data SlotDefaultValueSpec = SlotDefaultValueSpec'
  { -- | The default values for a slot. You can specify more than one default.
    -- For example, you can specify a default value to use from a matching
    -- context variable, a session attribute, or a fixed value.
    --
    -- The default value chosen is selected based on the order that you specify
    -- them in the list. For example, if you specify a context variable and a
    -- fixed value in that order, Amazon Lex uses the context variable if it is
    -- available, else it uses the fixed value.
    SlotDefaultValueSpec -> [SlotDefaultValue]
defaultValueList :: [SlotDefaultValue]
  }
  deriving (SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool
(SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool)
-> (SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool)
-> Eq SlotDefaultValueSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool
$c/= :: SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool
== :: SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool
$c== :: SlotDefaultValueSpec -> SlotDefaultValueSpec -> Bool
Prelude.Eq, ReadPrec [SlotDefaultValueSpec]
ReadPrec SlotDefaultValueSpec
Int -> ReadS SlotDefaultValueSpec
ReadS [SlotDefaultValueSpec]
(Int -> ReadS SlotDefaultValueSpec)
-> ReadS [SlotDefaultValueSpec]
-> ReadPrec SlotDefaultValueSpec
-> ReadPrec [SlotDefaultValueSpec]
-> Read SlotDefaultValueSpec
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SlotDefaultValueSpec]
$creadListPrec :: ReadPrec [SlotDefaultValueSpec]
readPrec :: ReadPrec SlotDefaultValueSpec
$creadPrec :: ReadPrec SlotDefaultValueSpec
readList :: ReadS [SlotDefaultValueSpec]
$creadList :: ReadS [SlotDefaultValueSpec]
readsPrec :: Int -> ReadS SlotDefaultValueSpec
$creadsPrec :: Int -> ReadS SlotDefaultValueSpec
Prelude.Read, Int -> SlotDefaultValueSpec -> ShowS
[SlotDefaultValueSpec] -> ShowS
SlotDefaultValueSpec -> String
(Int -> SlotDefaultValueSpec -> ShowS)
-> (SlotDefaultValueSpec -> String)
-> ([SlotDefaultValueSpec] -> ShowS)
-> Show SlotDefaultValueSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SlotDefaultValueSpec] -> ShowS
$cshowList :: [SlotDefaultValueSpec] -> ShowS
show :: SlotDefaultValueSpec -> String
$cshow :: SlotDefaultValueSpec -> String
showsPrec :: Int -> SlotDefaultValueSpec -> ShowS
$cshowsPrec :: Int -> SlotDefaultValueSpec -> ShowS
Prelude.Show, (forall x. SlotDefaultValueSpec -> Rep SlotDefaultValueSpec x)
-> (forall x. Rep SlotDefaultValueSpec x -> SlotDefaultValueSpec)
-> Generic SlotDefaultValueSpec
forall x. Rep SlotDefaultValueSpec x -> SlotDefaultValueSpec
forall x. SlotDefaultValueSpec -> Rep SlotDefaultValueSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SlotDefaultValueSpec x -> SlotDefaultValueSpec
$cfrom :: forall x. SlotDefaultValueSpec -> Rep SlotDefaultValueSpec x
Prelude.Generic)

-- |
-- Create a value of 'SlotDefaultValueSpec' 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:
--
-- 'defaultValueList', 'slotDefaultValueSpec_defaultValueList' - The default values for a slot. You can specify more than one default.
-- For example, you can specify a default value to use from a matching
-- context variable, a session attribute, or a fixed value.
--
-- The default value chosen is selected based on the order that you specify
-- them in the list. For example, if you specify a context variable and a
-- fixed value in that order, Amazon Lex uses the context variable if it is
-- available, else it uses the fixed value.
newSlotDefaultValueSpec ::
  SlotDefaultValueSpec
newSlotDefaultValueSpec :: SlotDefaultValueSpec
newSlotDefaultValueSpec =
  SlotDefaultValueSpec' :: [SlotDefaultValue] -> SlotDefaultValueSpec
SlotDefaultValueSpec'
    { $sel:defaultValueList:SlotDefaultValueSpec' :: [SlotDefaultValue]
defaultValueList =
        [SlotDefaultValue]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The default values for a slot. You can specify more than one default.
-- For example, you can specify a default value to use from a matching
-- context variable, a session attribute, or a fixed value.
--
-- The default value chosen is selected based on the order that you specify
-- them in the list. For example, if you specify a context variable and a
-- fixed value in that order, Amazon Lex uses the context variable if it is
-- available, else it uses the fixed value.
slotDefaultValueSpec_defaultValueList :: Lens.Lens' SlotDefaultValueSpec [SlotDefaultValue]
slotDefaultValueSpec_defaultValueList :: ([SlotDefaultValue] -> f [SlotDefaultValue])
-> SlotDefaultValueSpec -> f SlotDefaultValueSpec
slotDefaultValueSpec_defaultValueList = (SlotDefaultValueSpec -> [SlotDefaultValue])
-> (SlotDefaultValueSpec
    -> [SlotDefaultValue] -> SlotDefaultValueSpec)
-> Lens
     SlotDefaultValueSpec
     SlotDefaultValueSpec
     [SlotDefaultValue]
     [SlotDefaultValue]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SlotDefaultValueSpec' {[SlotDefaultValue]
defaultValueList :: [SlotDefaultValue]
$sel:defaultValueList:SlotDefaultValueSpec' :: SlotDefaultValueSpec -> [SlotDefaultValue]
defaultValueList} -> [SlotDefaultValue]
defaultValueList) (\s :: SlotDefaultValueSpec
s@SlotDefaultValueSpec' {} [SlotDefaultValue]
a -> SlotDefaultValueSpec
s {$sel:defaultValueList:SlotDefaultValueSpec' :: [SlotDefaultValue]
defaultValueList = [SlotDefaultValue]
a} :: SlotDefaultValueSpec) (([SlotDefaultValue] -> f [SlotDefaultValue])
 -> SlotDefaultValueSpec -> f SlotDefaultValueSpec)
-> (([SlotDefaultValue] -> f [SlotDefaultValue])
    -> [SlotDefaultValue] -> f [SlotDefaultValue])
-> ([SlotDefaultValue] -> f [SlotDefaultValue])
-> SlotDefaultValueSpec
-> f SlotDefaultValueSpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([SlotDefaultValue] -> f [SlotDefaultValue])
-> [SlotDefaultValue] -> f [SlotDefaultValue]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON SlotDefaultValueSpec where
  parseJSON :: Value -> Parser SlotDefaultValueSpec
parseJSON =
    String
-> (Object -> Parser SlotDefaultValueSpec)
-> Value
-> Parser SlotDefaultValueSpec
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SlotDefaultValueSpec"
      ( \Object
x ->
          [SlotDefaultValue] -> SlotDefaultValueSpec
SlotDefaultValueSpec'
            ([SlotDefaultValue] -> SlotDefaultValueSpec)
-> Parser [SlotDefaultValue] -> Parser SlotDefaultValueSpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe [SlotDefaultValue])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"defaultValueList"
                            Parser (Maybe [SlotDefaultValue])
-> [SlotDefaultValue] -> Parser [SlotDefaultValue]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [SlotDefaultValue]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable SlotDefaultValueSpec

instance Prelude.NFData SlotDefaultValueSpec

instance Core.ToJSON SlotDefaultValueSpec where
  toJSON :: SlotDefaultValueSpec -> Value
toJSON SlotDefaultValueSpec' {[SlotDefaultValue]
defaultValueList :: [SlotDefaultValue]
$sel:defaultValueList:SlotDefaultValueSpec' :: SlotDefaultValueSpec -> [SlotDefaultValue]
..} =
    [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
"defaultValueList" Text -> [SlotDefaultValue] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [SlotDefaultValue]
defaultValueList)
          ]
      )