{-# 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.Discovery.Types.OrderByElement
-- 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.Discovery.Types.OrderByElement where

import qualified Amazonka.Core as Core
import Amazonka.Discovery.Types.OrderString
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A field and direction for ordered output.
--
-- /See:/ 'newOrderByElement' smart constructor.
data OrderByElement = OrderByElement'
  { -- | Ordering direction.
    OrderByElement -> Maybe OrderString
sortOrder :: Prelude.Maybe OrderString,
    -- | The field on which to order.
    OrderByElement -> Text
fieldName :: Prelude.Text
  }
  deriving (OrderByElement -> OrderByElement -> Bool
(OrderByElement -> OrderByElement -> Bool)
-> (OrderByElement -> OrderByElement -> Bool) -> Eq OrderByElement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrderByElement -> OrderByElement -> Bool
$c/= :: OrderByElement -> OrderByElement -> Bool
== :: OrderByElement -> OrderByElement -> Bool
$c== :: OrderByElement -> OrderByElement -> Bool
Prelude.Eq, ReadPrec [OrderByElement]
ReadPrec OrderByElement
Int -> ReadS OrderByElement
ReadS [OrderByElement]
(Int -> ReadS OrderByElement)
-> ReadS [OrderByElement]
-> ReadPrec OrderByElement
-> ReadPrec [OrderByElement]
-> Read OrderByElement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OrderByElement]
$creadListPrec :: ReadPrec [OrderByElement]
readPrec :: ReadPrec OrderByElement
$creadPrec :: ReadPrec OrderByElement
readList :: ReadS [OrderByElement]
$creadList :: ReadS [OrderByElement]
readsPrec :: Int -> ReadS OrderByElement
$creadsPrec :: Int -> ReadS OrderByElement
Prelude.Read, Int -> OrderByElement -> ShowS
[OrderByElement] -> ShowS
OrderByElement -> String
(Int -> OrderByElement -> ShowS)
-> (OrderByElement -> String)
-> ([OrderByElement] -> ShowS)
-> Show OrderByElement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrderByElement] -> ShowS
$cshowList :: [OrderByElement] -> ShowS
show :: OrderByElement -> String
$cshow :: OrderByElement -> String
showsPrec :: Int -> OrderByElement -> ShowS
$cshowsPrec :: Int -> OrderByElement -> ShowS
Prelude.Show, (forall x. OrderByElement -> Rep OrderByElement x)
-> (forall x. Rep OrderByElement x -> OrderByElement)
-> Generic OrderByElement
forall x. Rep OrderByElement x -> OrderByElement
forall x. OrderByElement -> Rep OrderByElement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OrderByElement x -> OrderByElement
$cfrom :: forall x. OrderByElement -> Rep OrderByElement x
Prelude.Generic)

-- |
-- Create a value of 'OrderByElement' 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', 'orderByElement_sortOrder' - Ordering direction.
--
-- 'fieldName', 'orderByElement_fieldName' - The field on which to order.
newOrderByElement ::
  -- | 'fieldName'
  Prelude.Text ->
  OrderByElement
newOrderByElement :: Text -> OrderByElement
newOrderByElement Text
pFieldName_ =
  OrderByElement' :: Maybe OrderString -> Text -> OrderByElement
OrderByElement'
    { $sel:sortOrder:OrderByElement' :: Maybe OrderString
sortOrder = Maybe OrderString
forall a. Maybe a
Prelude.Nothing,
      $sel:fieldName:OrderByElement' :: Text
fieldName = Text
pFieldName_
    }

-- | Ordering direction.
orderByElement_sortOrder :: Lens.Lens' OrderByElement (Prelude.Maybe OrderString)
orderByElement_sortOrder :: (Maybe OrderString -> f (Maybe OrderString))
-> OrderByElement -> f OrderByElement
orderByElement_sortOrder = (OrderByElement -> Maybe OrderString)
-> (OrderByElement -> Maybe OrderString -> OrderByElement)
-> Lens
     OrderByElement
     OrderByElement
     (Maybe OrderString)
     (Maybe OrderString)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrderByElement' {Maybe OrderString
sortOrder :: Maybe OrderString
$sel:sortOrder:OrderByElement' :: OrderByElement -> Maybe OrderString
sortOrder} -> Maybe OrderString
sortOrder) (\s :: OrderByElement
s@OrderByElement' {} Maybe OrderString
a -> OrderByElement
s {$sel:sortOrder:OrderByElement' :: Maybe OrderString
sortOrder = Maybe OrderString
a} :: OrderByElement)

-- | The field on which to order.
orderByElement_fieldName :: Lens.Lens' OrderByElement Prelude.Text
orderByElement_fieldName :: (Text -> f Text) -> OrderByElement -> f OrderByElement
orderByElement_fieldName = (OrderByElement -> Text)
-> (OrderByElement -> Text -> OrderByElement)
-> Lens OrderByElement OrderByElement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OrderByElement' {Text
fieldName :: Text
$sel:fieldName:OrderByElement' :: OrderByElement -> Text
fieldName} -> Text
fieldName) (\s :: OrderByElement
s@OrderByElement' {} Text
a -> OrderByElement
s {$sel:fieldName:OrderByElement' :: Text
fieldName = Text
a} :: OrderByElement)

instance Prelude.Hashable OrderByElement

instance Prelude.NFData OrderByElement

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