{-# 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.AlexaBusiness.Types.Sort
-- 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.AlexaBusiness.Types.Sort where

import Amazonka.AlexaBusiness.Types.SortValue
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing a sort criteria.
--
-- /See:/ 'newSort' smart constructor.
data Sort = Sort'
  { -- | The sort key of a sort object.
    Sort -> Text
key :: Prelude.Text,
    -- | The sort value of a sort object.
    Sort -> SortValue
value :: SortValue
  }
  deriving (Sort -> Sort -> Bool
(Sort -> Sort -> Bool) -> (Sort -> Sort -> Bool) -> Eq Sort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Sort -> Sort -> Bool
$c/= :: Sort -> Sort -> Bool
== :: Sort -> Sort -> Bool
$c== :: Sort -> Sort -> Bool
Prelude.Eq, ReadPrec [Sort]
ReadPrec Sort
Int -> ReadS Sort
ReadS [Sort]
(Int -> ReadS Sort)
-> ReadS [Sort] -> ReadPrec Sort -> ReadPrec [Sort] -> Read Sort
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Sort]
$creadListPrec :: ReadPrec [Sort]
readPrec :: ReadPrec Sort
$creadPrec :: ReadPrec Sort
readList :: ReadS [Sort]
$creadList :: ReadS [Sort]
readsPrec :: Int -> ReadS Sort
$creadsPrec :: Int -> ReadS Sort
Prelude.Read, Int -> Sort -> ShowS
[Sort] -> ShowS
Sort -> String
(Int -> Sort -> ShowS)
-> (Sort -> String) -> ([Sort] -> ShowS) -> Show Sort
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Sort] -> ShowS
$cshowList :: [Sort] -> ShowS
show :: Sort -> String
$cshow :: Sort -> String
showsPrec :: Int -> Sort -> ShowS
$cshowsPrec :: Int -> Sort -> ShowS
Prelude.Show, (forall x. Sort -> Rep Sort x)
-> (forall x. Rep Sort x -> Sort) -> Generic Sort
forall x. Rep Sort x -> Sort
forall x. Sort -> Rep Sort x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Sort x -> Sort
$cfrom :: forall x. Sort -> Rep Sort x
Prelude.Generic)

-- |
-- Create a value of 'Sort' 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:
--
-- 'key', 'sort_key' - The sort key of a sort object.
--
-- 'value', 'sort_value' - The sort value of a sort object.
newSort ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  SortValue ->
  Sort
newSort :: Text -> SortValue -> Sort
newSort Text
pKey_ SortValue
pValue_ =
  Sort' :: Text -> SortValue -> Sort
Sort' {$sel:key:Sort' :: Text
key = Text
pKey_, $sel:value:Sort' :: SortValue
value = SortValue
pValue_}

-- | The sort key of a sort object.
sort_key :: Lens.Lens' Sort Prelude.Text
sort_key :: (Text -> f Text) -> Sort -> f Sort
sort_key = (Sort -> Text)
-> (Sort -> Text -> Sort) -> Lens Sort Sort Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sort' {Text
key :: Text
$sel:key:Sort' :: Sort -> Text
key} -> Text
key) (\s :: Sort
s@Sort' {} Text
a -> Sort
s {$sel:key:Sort' :: Text
key = Text
a} :: Sort)

-- | The sort value of a sort object.
sort_value :: Lens.Lens' Sort SortValue
sort_value :: (SortValue -> f SortValue) -> Sort -> f Sort
sort_value = (Sort -> SortValue)
-> (Sort -> SortValue -> Sort)
-> Lens Sort Sort SortValue SortValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sort' {SortValue
value :: SortValue
$sel:value:Sort' :: Sort -> SortValue
value} -> SortValue
value) (\s :: Sort
s@Sort' {} SortValue
a -> Sort
s {$sel:value:Sort' :: SortValue
value = SortValue
a} :: Sort)

instance Prelude.Hashable Sort

instance Prelude.NFData Sort

instance Core.ToJSON Sort where
  toJSON :: Sort -> Value
toJSON Sort' {Text
SortValue
value :: SortValue
key :: Text
$sel:value:Sort' :: Sort -> SortValue
$sel:key:Sort' :: Sort -> Text
..} =
    [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
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> SortValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SortValue
value)
          ]
      )