{-# 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.ConnectCases.Types.FieldValue
-- 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.ConnectCases.Types.FieldValue where

import Amazonka.ConnectCases.Types.FieldValueUnion
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

-- | Object for case field values.
--
-- /See:/ 'newFieldValue' smart constructor.
data FieldValue = FieldValue'
  { -- | Unique identifier of a field.
    FieldValue -> Text
id :: Prelude.Text,
    -- | Union of potential field value types.
    FieldValue -> FieldValueUnion
value :: FieldValueUnion
  }
  deriving (FieldValue -> FieldValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldValue -> FieldValue -> Bool
$c/= :: FieldValue -> FieldValue -> Bool
== :: FieldValue -> FieldValue -> Bool
$c== :: FieldValue -> FieldValue -> Bool
Prelude.Eq, ReadPrec [FieldValue]
ReadPrec FieldValue
Int -> ReadS FieldValue
ReadS [FieldValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldValue]
$creadListPrec :: ReadPrec [FieldValue]
readPrec :: ReadPrec FieldValue
$creadPrec :: ReadPrec FieldValue
readList :: ReadS [FieldValue]
$creadList :: ReadS [FieldValue]
readsPrec :: Int -> ReadS FieldValue
$creadsPrec :: Int -> ReadS FieldValue
Prelude.Read, Int -> FieldValue -> ShowS
[FieldValue] -> ShowS
FieldValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldValue] -> ShowS
$cshowList :: [FieldValue] -> ShowS
show :: FieldValue -> String
$cshow :: FieldValue -> String
showsPrec :: Int -> FieldValue -> ShowS
$cshowsPrec :: Int -> FieldValue -> ShowS
Prelude.Show, forall x. Rep FieldValue x -> FieldValue
forall x. FieldValue -> Rep FieldValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldValue x -> FieldValue
$cfrom :: forall x. FieldValue -> Rep FieldValue x
Prelude.Generic)

-- |
-- Create a value of 'FieldValue' 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:
--
-- 'id', 'fieldValue_id' - Unique identifier of a field.
--
-- 'value', 'fieldValue_value' - Union of potential field value types.
newFieldValue ::
  -- | 'id'
  Prelude.Text ->
  -- | 'value'
  FieldValueUnion ->
  FieldValue
newFieldValue :: Text -> FieldValueUnion -> FieldValue
newFieldValue Text
pId_ FieldValueUnion
pValue_ =
  FieldValue' {$sel:id:FieldValue' :: Text
id = Text
pId_, $sel:value:FieldValue' :: FieldValueUnion
value = FieldValueUnion
pValue_}

-- | Unique identifier of a field.
fieldValue_id :: Lens.Lens' FieldValue Prelude.Text
fieldValue_id :: Lens' FieldValue Text
fieldValue_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldValue' {Text
id :: Text
$sel:id:FieldValue' :: FieldValue -> Text
id} -> Text
id) (\s :: FieldValue
s@FieldValue' {} Text
a -> FieldValue
s {$sel:id:FieldValue' :: Text
id = Text
a} :: FieldValue)

-- | Union of potential field value types.
fieldValue_value :: Lens.Lens' FieldValue FieldValueUnion
fieldValue_value :: Lens' FieldValue FieldValueUnion
fieldValue_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldValue' {FieldValueUnion
value :: FieldValueUnion
$sel:value:FieldValue' :: FieldValue -> FieldValueUnion
value} -> FieldValueUnion
value) (\s :: FieldValue
s@FieldValue' {} FieldValueUnion
a -> FieldValue
s {$sel:value:FieldValue' :: FieldValueUnion
value = FieldValueUnion
a} :: FieldValue)

instance Data.FromJSON FieldValue where
  parseJSON :: Value -> Parser FieldValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FieldValue"
      ( \Object
x ->
          Text -> FieldValueUnion -> FieldValue
FieldValue'
            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
"id")
            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
"value")
      )

instance Prelude.Hashable FieldValue where
  hashWithSalt :: Int -> FieldValue -> Int
hashWithSalt Int
_salt FieldValue' {Text
FieldValueUnion
value :: FieldValueUnion
id :: Text
$sel:value:FieldValue' :: FieldValue -> FieldValueUnion
$sel:id:FieldValue' :: FieldValue -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FieldValueUnion
value

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

instance Data.ToJSON FieldValue where
  toJSON :: FieldValue -> Value
toJSON FieldValue' {Text
FieldValueUnion
value :: FieldValueUnion
id :: Text
$sel:value:FieldValue' :: FieldValue -> FieldValueUnion
$sel:id:FieldValue' :: FieldValue -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FieldValueUnion
value)
          ]
      )