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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
    -- is @DESCENDING@.
    Sort -> Maybe SortOrder
sortOrder :: Prelude.Maybe SortOrder,
    -- | 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
  }
  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:
--
-- 'sortOrder', 'sort_sortOrder' - The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
-- is @DESCENDING@.
--
-- 'sortBy', 'sort_sortBy' - For @ListEntities@, supported attributes include @LastModifiedDate@
-- (default), @Visibility@, @EntityId@, and @Name@.
--
-- For @ListChangeSets@, supported attributes include @StartTime@ and
-- @EndTime@.
newSort ::
  Sort
newSort :: Sort
newSort =
  Sort' :: Maybe SortOrder -> Maybe Text -> Sort
Sort'
    { $sel:sortOrder:Sort' :: Maybe SortOrder
sortOrder = Maybe SortOrder
forall a. Maybe a
Prelude.Nothing,
      $sel:sortBy:Sort' :: Maybe Text
sortBy = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The sorting order. Can be @ASCENDING@ or @DESCENDING@. The default value
-- is @DESCENDING@.
sort_sortOrder :: Lens.Lens' Sort (Prelude.Maybe SortOrder)
sort_sortOrder :: (Maybe SortOrder -> f (Maybe SortOrder)) -> Sort -> f Sort
sort_sortOrder = (Sort -> Maybe SortOrder)
-> (Sort -> Maybe SortOrder -> Sort)
-> Lens Sort Sort (Maybe SortOrder) (Maybe 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)

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Sort -> f Sort
sort_sortBy = (Sort -> Maybe Text)
-> (Sort -> Maybe Text -> Sort)
-> Lens Sort Sort (Maybe Text) (Maybe Text)
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)

instance Prelude.Hashable Sort

instance Prelude.NFData Sort

instance Core.ToJSON Sort where
  toJSON :: Sort -> Value
toJSON Sort' {Maybe Text
Maybe SortOrder
sortBy :: Maybe Text
sortOrder :: Maybe SortOrder
$sel:sortBy:Sort' :: Sort -> Maybe Text
$sel:sortOrder:Sort' :: Sort -> Maybe SortOrder
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SortOrder" Text -> SortOrder -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SortOrder -> Pair) -> Maybe SortOrder -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SortOrder
sortOrder,
            (Text
"SortBy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sortBy
          ]
      )