{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' Sort Text
sort_key = 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 :: Lens' Sort SortValue
sort_value = 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 where
  hashWithSalt :: Int -> Sort -> Int
hashWithSalt Int
_salt Sort' {Text
SortValue
value :: SortValue
key :: Text
$sel:value:Sort' :: Sort -> SortValue
$sel:key:Sort' :: Sort -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SortValue
value

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key),
            forall a. a -> Maybe a
Prelude.Just (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SortValue
value)
          ]
      )