{-# 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.MacieV2.Types.SortCriteria
-- 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.MacieV2.Types.SortCriteria where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MacieV2.Types.OrderBy
import qualified Amazonka.Prelude as Prelude

-- | Specifies criteria for sorting the results of a request for findings.
--
-- /See:/ 'newSortCriteria' smart constructor.
data SortCriteria = SortCriteria'
  { -- | The sort order to apply to the results, based on the value for the
    -- property specified by the attributeName property. Valid values are: ASC,
    -- sort the results in ascending order; and, DESC, sort the results in
    -- descending order.
    SortCriteria -> Maybe OrderBy
orderBy :: Prelude.Maybe OrderBy,
    -- | The name of the property to sort the results by. This value can be the
    -- name of any property that Amazon Macie defines for a finding.
    SortCriteria -> Maybe Text
attributeName :: Prelude.Maybe Prelude.Text
  }
  deriving (SortCriteria -> SortCriteria -> Bool
(SortCriteria -> SortCriteria -> Bool)
-> (SortCriteria -> SortCriteria -> Bool) -> Eq SortCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SortCriteria -> SortCriteria -> Bool
$c/= :: SortCriteria -> SortCriteria -> Bool
== :: SortCriteria -> SortCriteria -> Bool
$c== :: SortCriteria -> SortCriteria -> Bool
Prelude.Eq, ReadPrec [SortCriteria]
ReadPrec SortCriteria
Int -> ReadS SortCriteria
ReadS [SortCriteria]
(Int -> ReadS SortCriteria)
-> ReadS [SortCriteria]
-> ReadPrec SortCriteria
-> ReadPrec [SortCriteria]
-> Read SortCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SortCriteria]
$creadListPrec :: ReadPrec [SortCriteria]
readPrec :: ReadPrec SortCriteria
$creadPrec :: ReadPrec SortCriteria
readList :: ReadS [SortCriteria]
$creadList :: ReadS [SortCriteria]
readsPrec :: Int -> ReadS SortCriteria
$creadsPrec :: Int -> ReadS SortCriteria
Prelude.Read, Int -> SortCriteria -> ShowS
[SortCriteria] -> ShowS
SortCriteria -> String
(Int -> SortCriteria -> ShowS)
-> (SortCriteria -> String)
-> ([SortCriteria] -> ShowS)
-> Show SortCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SortCriteria] -> ShowS
$cshowList :: [SortCriteria] -> ShowS
show :: SortCriteria -> String
$cshow :: SortCriteria -> String
showsPrec :: Int -> SortCriteria -> ShowS
$cshowsPrec :: Int -> SortCriteria -> ShowS
Prelude.Show, (forall x. SortCriteria -> Rep SortCriteria x)
-> (forall x. Rep SortCriteria x -> SortCriteria)
-> Generic SortCriteria
forall x. Rep SortCriteria x -> SortCriteria
forall x. SortCriteria -> Rep SortCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SortCriteria x -> SortCriteria
$cfrom :: forall x. SortCriteria -> Rep SortCriteria x
Prelude.Generic)

-- |
-- Create a value of 'SortCriteria' 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:
--
-- 'orderBy', 'sortCriteria_orderBy' - The sort order to apply to the results, based on the value for the
-- property specified by the attributeName property. Valid values are: ASC,
-- sort the results in ascending order; and, DESC, sort the results in
-- descending order.
--
-- 'attributeName', 'sortCriteria_attributeName' - The name of the property to sort the results by. This value can be the
-- name of any property that Amazon Macie defines for a finding.
newSortCriteria ::
  SortCriteria
newSortCriteria :: SortCriteria
newSortCriteria =
  SortCriteria' :: Maybe OrderBy -> Maybe Text -> SortCriteria
SortCriteria'
    { $sel:orderBy:SortCriteria' :: Maybe OrderBy
orderBy = Maybe OrderBy
forall a. Maybe a
Prelude.Nothing,
      $sel:attributeName:SortCriteria' :: Maybe Text
attributeName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The sort order to apply to the results, based on the value for the
-- property specified by the attributeName property. Valid values are: ASC,
-- sort the results in ascending order; and, DESC, sort the results in
-- descending order.
sortCriteria_orderBy :: Lens.Lens' SortCriteria (Prelude.Maybe OrderBy)
sortCriteria_orderBy :: (Maybe OrderBy -> f (Maybe OrderBy))
-> SortCriteria -> f SortCriteria
sortCriteria_orderBy = (SortCriteria -> Maybe OrderBy)
-> (SortCriteria -> Maybe OrderBy -> SortCriteria)
-> Lens SortCriteria SortCriteria (Maybe OrderBy) (Maybe OrderBy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriteria' {Maybe OrderBy
orderBy :: Maybe OrderBy
$sel:orderBy:SortCriteria' :: SortCriteria -> Maybe OrderBy
orderBy} -> Maybe OrderBy
orderBy) (\s :: SortCriteria
s@SortCriteria' {} Maybe OrderBy
a -> SortCriteria
s {$sel:orderBy:SortCriteria' :: Maybe OrderBy
orderBy = Maybe OrderBy
a} :: SortCriteria)

-- | The name of the property to sort the results by. This value can be the
-- name of any property that Amazon Macie defines for a finding.
sortCriteria_attributeName :: Lens.Lens' SortCriteria (Prelude.Maybe Prelude.Text)
sortCriteria_attributeName :: (Maybe Text -> f (Maybe Text)) -> SortCriteria -> f SortCriteria
sortCriteria_attributeName = (SortCriteria -> Maybe Text)
-> (SortCriteria -> Maybe Text -> SortCriteria)
-> Lens SortCriteria SortCriteria (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriteria' {Maybe Text
attributeName :: Maybe Text
$sel:attributeName:SortCriteria' :: SortCriteria -> Maybe Text
attributeName} -> Maybe Text
attributeName) (\s :: SortCriteria
s@SortCriteria' {} Maybe Text
a -> SortCriteria
s {$sel:attributeName:SortCriteria' :: Maybe Text
attributeName = Maybe Text
a} :: SortCriteria)

instance Prelude.Hashable SortCriteria

instance Prelude.NFData SortCriteria

instance Core.ToJSON SortCriteria where
  toJSON :: SortCriteria -> Value
toJSON SortCriteria' {Maybe Text
Maybe OrderBy
attributeName :: Maybe Text
orderBy :: Maybe OrderBy
$sel:attributeName:SortCriteria' :: SortCriteria -> Maybe Text
$sel:orderBy:SortCriteria' :: SortCriteria -> Maybe OrderBy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"orderBy" Text -> OrderBy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (OrderBy -> Pair) -> Maybe OrderBy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OrderBy
orderBy,
            (Text
"attributeName" 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
attributeName
          ]
      )