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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SecurityHub.Types.SortOrder

-- | A collection of finding attributes used to sort findings.
--
-- /See:/ 'newSortCriterion' smart constructor.
data SortCriterion = SortCriterion'
  { -- | The finding attribute used to sort findings.
    SortCriterion -> Maybe Text
field :: Prelude.Maybe Prelude.Text,
    -- | The order used to sort findings.
    SortCriterion -> Maybe SortOrder
sortOrder :: Prelude.Maybe SortOrder
  }
  deriving (SortCriterion -> SortCriterion -> Bool
(SortCriterion -> SortCriterion -> Bool)
-> (SortCriterion -> SortCriterion -> Bool) -> Eq SortCriterion
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]
(Int -> ReadS SortCriterion)
-> ReadS [SortCriterion]
-> ReadPrec SortCriterion
-> ReadPrec [SortCriterion]
-> Read 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
(Int -> SortCriterion -> ShowS)
-> (SortCriterion -> String)
-> ([SortCriterion] -> ShowS)
-> Show SortCriterion
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. SortCriterion -> Rep SortCriterion x)
-> (forall x. Rep SortCriterion x -> SortCriterion)
-> Generic SortCriterion
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:
--
-- 'field', 'sortCriterion_field' - The finding attribute used to sort findings.
--
-- 'sortOrder', 'sortCriterion_sortOrder' - The order used to sort findings.
newSortCriterion ::
  SortCriterion
newSortCriterion :: SortCriterion
newSortCriterion =
  SortCriterion' :: Maybe Text -> Maybe SortOrder -> SortCriterion
SortCriterion'
    { $sel:field:SortCriterion' :: Maybe Text
field = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sortOrder:SortCriterion' :: Maybe SortOrder
sortOrder = Maybe SortOrder
forall a. Maybe a
Prelude.Nothing
    }

-- | The finding attribute used to sort findings.
sortCriterion_field :: Lens.Lens' SortCriterion (Prelude.Maybe Prelude.Text)
sortCriterion_field :: (Maybe Text -> f (Maybe Text)) -> SortCriterion -> f SortCriterion
sortCriterion_field = (SortCriterion -> Maybe Text)
-> (SortCriterion -> Maybe Text -> SortCriterion)
-> Lens SortCriterion SortCriterion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriterion' {Maybe Text
field :: Maybe Text
$sel:field:SortCriterion' :: SortCriterion -> Maybe Text
field} -> Maybe Text
field) (\s :: SortCriterion
s@SortCriterion' {} Maybe Text
a -> SortCriterion
s {$sel:field:SortCriterion' :: Maybe Text
field = Maybe Text
a} :: SortCriterion)

-- | The order used to sort findings.
sortCriterion_sortOrder :: Lens.Lens' SortCriterion (Prelude.Maybe SortOrder)
sortCriterion_sortOrder :: (Maybe SortOrder -> f (Maybe SortOrder))
-> SortCriterion -> f SortCriterion
sortCriterion_sortOrder = (SortCriterion -> Maybe SortOrder)
-> (SortCriterion -> Maybe SortOrder -> SortCriterion)
-> Lens
     SortCriterion SortCriterion (Maybe SortOrder) (Maybe SortOrder)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCriterion' {Maybe SortOrder
sortOrder :: Maybe SortOrder
$sel:sortOrder:SortCriterion' :: SortCriterion -> Maybe SortOrder
sortOrder} -> Maybe SortOrder
sortOrder) (\s :: SortCriterion
s@SortCriterion' {} Maybe SortOrder
a -> SortCriterion
s {$sel:sortOrder:SortCriterion' :: Maybe SortOrder
sortOrder = Maybe SortOrder
a} :: SortCriterion)

instance Prelude.Hashable SortCriterion

instance Prelude.NFData SortCriterion

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