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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MarketplaceCatalog.Types.SortOrder
import qualified Amazonka.Prelude as Prelude

-- | An object that contains two attributes, @SortBy@ and @SortOrder@.
--
-- /See:/ 'newSort' smart constructor.
data Sort = Sort'
  { -- | For @ListEntities@, supported attributes include @LastModifiedDate@
    -- (default), @Visibility@, @EntityId@, and @Name@.
    --
    -- For @ListChangeSets@, supported attributes include @StartTime@ and
    -- @EndTime@.
    Sort -> Maybe Text
sortBy :: Prelude.Maybe Prelude.Text,
    -- | The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
    -- is @DESCENDING@.
    Sort -> Maybe SortOrder
sortOrder :: Prelude.Maybe SortOrder
  }
  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:
--
-- 'sortBy', 'sort_sortBy' - For @ListEntities@, supported attributes include @LastModifiedDate@
-- (default), @Visibility@, @EntityId@, and @Name@.
--
-- For @ListChangeSets@, supported attributes include @StartTime@ and
-- @EndTime@.
--
-- 'sortOrder', 'sort_sortOrder' - The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
-- is @DESCENDING@.
newSort ::
  Sort
newSort :: Sort
newSort =
  Sort'
    { $sel:sortBy:Sort' :: Maybe Text
sortBy = forall a. Maybe a
Prelude.Nothing,
      $sel:sortOrder:Sort' :: Maybe SortOrder
sortOrder = forall a. Maybe a
Prelude.Nothing
    }

-- | For @ListEntities@, supported attributes include @LastModifiedDate@
-- (default), @Visibility@, @EntityId@, and @Name@.
--
-- For @ListChangeSets@, supported attributes include @StartTime@ and
-- @EndTime@.
sort_sortBy :: Lens.Lens' Sort (Prelude.Maybe Prelude.Text)
sort_sortBy :: Lens' Sort (Maybe Text)
sort_sortBy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sort' {Maybe Text
sortBy :: Maybe Text
$sel:sortBy:Sort' :: Sort -> Maybe Text
sortBy} -> Maybe Text
sortBy) (\s :: Sort
s@Sort' {} Maybe Text
a -> Sort
s {$sel:sortBy:Sort' :: Maybe Text
sortBy = Maybe Text
a} :: Sort)

-- | The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
-- is @DESCENDING@.
sort_sortOrder :: Lens.Lens' Sort (Prelude.Maybe SortOrder)
sort_sortOrder :: Lens' Sort (Maybe SortOrder)
sort_sortOrder = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sort' {Maybe SortOrder
sortOrder :: Maybe SortOrder
$sel:sortOrder:Sort' :: Sort -> Maybe SortOrder
sortOrder} -> Maybe SortOrder
sortOrder) (\s :: Sort
s@Sort' {} Maybe SortOrder
a -> Sort
s {$sel:sortOrder:Sort' :: Maybe SortOrder
sortOrder = Maybe SortOrder
a} :: Sort)

instance Prelude.Hashable Sort where
  hashWithSalt :: Int -> Sort -> Int
hashWithSalt Int
_salt Sort' {Maybe Text
Maybe SortOrder
sortOrder :: Maybe SortOrder
sortBy :: Maybe Text
$sel:sortOrder:Sort' :: Sort -> Maybe SortOrder
$sel:sortBy:Sort' :: Sort -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sortBy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SortOrder
sortOrder

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

instance Data.ToJSON Sort where
  toJSON :: Sort -> Value
toJSON Sort' {Maybe Text
Maybe SortOrder
sortOrder :: Maybe SortOrder
sortBy :: Maybe Text
$sel:sortOrder:Sort' :: Sort -> Maybe SortOrder
$sel:sortBy:Sort' :: Sort -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SortBy" 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
sortBy,
            (Key
"SortOrder" 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 SortOrder
sortOrder
          ]
      )