{-# 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.Connect.Types.Reference
-- 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.Connect.Types.Reference where

import Amazonka.Connect.Types.ReferenceType
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

-- | Well-formed data on a contact, used by agents to complete a contact
-- request. You can have up to 4,096 UTF-8 bytes across all references for
-- a contact.
--
-- /See:/ 'newReference' smart constructor.
data Reference = Reference'
  { -- | A valid value for the reference. For example, for a URL reference, a
    -- formatted URL that is displayed to an agent in the Contact Control Panel
    -- (CCP).
    Reference -> Text
value :: Prelude.Text,
    -- | The type of the reference. @DATE@ must be of type Epoch timestamp.
    Reference -> ReferenceType
type' :: ReferenceType
  }
  deriving (Reference -> Reference -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Reference -> Reference -> Bool
$c/= :: Reference -> Reference -> Bool
== :: Reference -> Reference -> Bool
$c== :: Reference -> Reference -> Bool
Prelude.Eq, ReadPrec [Reference]
ReadPrec Reference
Int -> ReadS Reference
ReadS [Reference]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Reference]
$creadListPrec :: ReadPrec [Reference]
readPrec :: ReadPrec Reference
$creadPrec :: ReadPrec Reference
readList :: ReadS [Reference]
$creadList :: ReadS [Reference]
readsPrec :: Int -> ReadS Reference
$creadsPrec :: Int -> ReadS Reference
Prelude.Read, Int -> Reference -> ShowS
[Reference] -> ShowS
Reference -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Reference] -> ShowS
$cshowList :: [Reference] -> ShowS
show :: Reference -> String
$cshow :: Reference -> String
showsPrec :: Int -> Reference -> ShowS
$cshowsPrec :: Int -> Reference -> ShowS
Prelude.Show, forall x. Rep Reference x -> Reference
forall x. Reference -> Rep Reference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Reference x -> Reference
$cfrom :: forall x. Reference -> Rep Reference x
Prelude.Generic)

-- |
-- Create a value of 'Reference' 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:
--
-- 'value', 'reference_value' - A valid value for the reference. For example, for a URL reference, a
-- formatted URL that is displayed to an agent in the Contact Control Panel
-- (CCP).
--
-- 'type'', 'reference_type' - The type of the reference. @DATE@ must be of type Epoch timestamp.
newReference ::
  -- | 'value'
  Prelude.Text ->
  -- | 'type''
  ReferenceType ->
  Reference
newReference :: Text -> ReferenceType -> Reference
newReference Text
pValue_ ReferenceType
pType_ =
  Reference' {$sel:value:Reference' :: Text
value = Text
pValue_, $sel:type':Reference' :: ReferenceType
type' = ReferenceType
pType_}

-- | A valid value for the reference. For example, for a URL reference, a
-- formatted URL that is displayed to an agent in the Contact Control Panel
-- (CCP).
reference_value :: Lens.Lens' Reference Prelude.Text
reference_value :: Lens' Reference Text
reference_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Reference' {Text
value :: Text
$sel:value:Reference' :: Reference -> Text
value} -> Text
value) (\s :: Reference
s@Reference' {} Text
a -> Reference
s {$sel:value:Reference' :: Text
value = Text
a} :: Reference)

-- | The type of the reference. @DATE@ must be of type Epoch timestamp.
reference_type :: Lens.Lens' Reference ReferenceType
reference_type :: Lens' Reference ReferenceType
reference_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Reference' {ReferenceType
type' :: ReferenceType
$sel:type':Reference' :: Reference -> ReferenceType
type'} -> ReferenceType
type') (\s :: Reference
s@Reference' {} ReferenceType
a -> Reference
s {$sel:type':Reference' :: ReferenceType
type' = ReferenceType
a} :: Reference)

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

instance Prelude.Hashable Reference where
  hashWithSalt :: Int -> Reference -> Int
hashWithSalt Int
_salt Reference' {Text
ReferenceType
type' :: ReferenceType
value :: Text
$sel:type':Reference' :: Reference -> ReferenceType
$sel:value:Reference' :: Reference -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ReferenceType
type'

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

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