{-# 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.Glue.Types.SortCriterion
-- 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.Glue.Types.SortCriterion where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types.Sort
import qualified Amazonka.Prelude as Prelude

-- | Specifies a field to sort by and a sort order.
--
-- /See:/ 'newSortCriterion' smart constructor.
data SortCriterion = SortCriterion'
  { -- | The name of the field on which to sort.
    SortCriterion -> Maybe Text
fieldName :: Prelude.Maybe Prelude.Text,
    -- | An ascending or descending sort.
    SortCriterion -> Maybe Sort
sort :: Prelude.Maybe Sort
  }
  deriving (SortCriterion -> SortCriterion -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SortCriterion -> SortCriterion -> Bool
$c/= :: SortCriterion -> SortCriterion -> Bool
== :: SortCriterion -> SortCriterion -> Bool
$c== :: SortCriterion -> SortCriterion -> Bool
Prelude.Eq, ReadPrec [SortCriterion]
ReadPrec SortCriterion
Int -> ReadS SortCriterion
ReadS [SortCriterion]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SortCriterion]
$creadListPrec :: ReadPrec [SortCriterion]
readPrec :: ReadPrec SortCriterion
$creadPrec :: ReadPrec SortCriterion
readList :: ReadS [SortCriterion]
$creadList :: ReadS [SortCriterion]
readsPrec :: Int -> ReadS SortCriterion
$creadsPrec :: Int -> ReadS SortCriterion
Prelude.Read, Int -> SortCriterion -> ShowS
[SortCriterion] -> ShowS
SortCriterion -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SortCriterion] -> ShowS
$cshowList :: [SortCriterion] -> ShowS
show :: SortCriterion -> String
$cshow :: SortCriterion -> String
showsPrec :: Int -> SortCriterion -> ShowS
$cshowsPrec :: Int -> SortCriterion -> ShowS
Prelude.Show, forall x. Rep SortCriterion x -> SortCriterion
forall x. SortCriterion -> Rep SortCriterion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SortCriterion x -> SortCriterion
$cfrom :: forall x. SortCriterion -> Rep SortCriterion x
Prelude.Generic)

-- |
-- Create a value of 'SortCriterion' 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:
--
-- 'fieldName', 'sortCriterion_fieldName' - The name of the field on which to sort.
--
-- 'sort', 'sortCriterion_sort' - An ascending or descending sort.
newSortCriterion ::
  SortCriterion
newSortCriterion :: SortCriterion
newSortCriterion =
  SortCriterion'
    { $sel:fieldName:SortCriterion' :: Maybe Text
fieldName = forall a. Maybe a
Prelude.Nothing,
      $sel:sort:SortCriterion' :: Maybe Sort
sort = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the field on which to sort.
sortCriterion_fieldName :: Lens.Lens' SortCriterion (Prelude.Maybe Prelude.Text)
sortCriterion_fieldName :: Lens' SortCriterion (Maybe Text)
sortCriterion_fieldName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriterion' {Maybe Text
fieldName :: Maybe Text
$sel:fieldName:SortCriterion' :: SortCriterion -> Maybe Text
fieldName} -> Maybe Text
fieldName) (\s :: SortCriterion
s@SortCriterion' {} Maybe Text
a -> SortCriterion
s {$sel:fieldName:SortCriterion' :: Maybe Text
fieldName = Maybe Text
a} :: SortCriterion)

-- | An ascending or descending sort.
sortCriterion_sort :: Lens.Lens' SortCriterion (Prelude.Maybe Sort)
sortCriterion_sort :: Lens' SortCriterion (Maybe Sort)
sortCriterion_sort = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriterion' {Maybe Sort
sort :: Maybe Sort
$sel:sort:SortCriterion' :: SortCriterion -> Maybe Sort
sort} -> Maybe Sort
sort) (\s :: SortCriterion
s@SortCriterion' {} Maybe Sort
a -> SortCriterion
s {$sel:sort:SortCriterion' :: Maybe Sort
sort = Maybe Sort
a} :: SortCriterion)

instance Prelude.Hashable SortCriterion where
  hashWithSalt :: Int -> SortCriterion -> Int
hashWithSalt Int
_salt SortCriterion' {Maybe Text
Maybe Sort
sort :: Maybe Sort
fieldName :: Maybe Text
$sel:sort:SortCriterion' :: SortCriterion -> Maybe Sort
$sel:fieldName:SortCriterion' :: SortCriterion -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
fieldName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Sort
sort

instance Prelude.NFData SortCriterion where
  rnf :: SortCriterion -> ()
rnf SortCriterion' {Maybe Text
Maybe Sort
sort :: Maybe Sort
fieldName :: Maybe Text
$sel:sort:SortCriterion' :: SortCriterion -> Maybe Sort
$sel:fieldName:SortCriterion' :: SortCriterion -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
fieldName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Sort
sort

instance Data.ToJSON SortCriterion where
  toJSON :: SortCriterion -> Value
toJSON SortCriterion' {Maybe Text
Maybe Sort
sort :: Maybe Sort
fieldName :: Maybe Text
$sel:sort:SortCriterion' :: SortCriterion -> Maybe Sort
$sel:fieldName:SortCriterion' :: SortCriterion -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FieldName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
fieldName,
            (Key
"Sort" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Sort
sort
          ]
      )