{-# 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.CostExplorer.Types.SortDefinition
-- 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.CostExplorer.Types.SortDefinition where

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

-- | The details of how to sort the data.
--
-- /See:/ 'newSortDefinition' smart constructor.
data SortDefinition = SortDefinition'
  { -- | The order that\'s used to sort the data.
    SortDefinition -> Maybe SortOrder
sortOrder :: Prelude.Maybe SortOrder,
    -- | The key that\'s used to sort the data.
    SortDefinition -> Text
key :: Prelude.Text
  }
  deriving (SortDefinition -> SortDefinition -> Bool
(SortDefinition -> SortDefinition -> Bool)
-> (SortDefinition -> SortDefinition -> Bool) -> Eq SortDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SortDefinition -> SortDefinition -> Bool
$c/= :: SortDefinition -> SortDefinition -> Bool
== :: SortDefinition -> SortDefinition -> Bool
$c== :: SortDefinition -> SortDefinition -> Bool
Prelude.Eq, ReadPrec [SortDefinition]
ReadPrec SortDefinition
Int -> ReadS SortDefinition
ReadS [SortDefinition]
(Int -> ReadS SortDefinition)
-> ReadS [SortDefinition]
-> ReadPrec SortDefinition
-> ReadPrec [SortDefinition]
-> Read SortDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SortDefinition]
$creadListPrec :: ReadPrec [SortDefinition]
readPrec :: ReadPrec SortDefinition
$creadPrec :: ReadPrec SortDefinition
readList :: ReadS [SortDefinition]
$creadList :: ReadS [SortDefinition]
readsPrec :: Int -> ReadS SortDefinition
$creadsPrec :: Int -> ReadS SortDefinition
Prelude.Read, Int -> SortDefinition -> ShowS
[SortDefinition] -> ShowS
SortDefinition -> String
(Int -> SortDefinition -> ShowS)
-> (SortDefinition -> String)
-> ([SortDefinition] -> ShowS)
-> Show SortDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SortDefinition] -> ShowS
$cshowList :: [SortDefinition] -> ShowS
show :: SortDefinition -> String
$cshow :: SortDefinition -> String
showsPrec :: Int -> SortDefinition -> ShowS
$cshowsPrec :: Int -> SortDefinition -> ShowS
Prelude.Show, (forall x. SortDefinition -> Rep SortDefinition x)
-> (forall x. Rep SortDefinition x -> SortDefinition)
-> Generic SortDefinition
forall x. Rep SortDefinition x -> SortDefinition
forall x. SortDefinition -> Rep SortDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SortDefinition x -> SortDefinition
$cfrom :: forall x. SortDefinition -> Rep SortDefinition x
Prelude.Generic)

-- |
-- Create a value of 'SortDefinition' 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', 'sortDefinition_sortOrder' - The order that\'s used to sort the data.
--
-- 'key', 'sortDefinition_key' - The key that\'s used to sort the data.
newSortDefinition ::
  -- | 'key'
  Prelude.Text ->
  SortDefinition
newSortDefinition :: Text -> SortDefinition
newSortDefinition Text
pKey_ =
  SortDefinition' :: Maybe SortOrder -> Text -> SortDefinition
SortDefinition'
    { $sel:sortOrder:SortDefinition' :: Maybe SortOrder
sortOrder = Maybe SortOrder
forall a. Maybe a
Prelude.Nothing,
      $sel:key:SortDefinition' :: Text
key = Text
pKey_
    }

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

-- | The key that\'s used to sort the data.
sortDefinition_key :: Lens.Lens' SortDefinition Prelude.Text
sortDefinition_key :: (Text -> f Text) -> SortDefinition -> f SortDefinition
sortDefinition_key = (SortDefinition -> Text)
-> (SortDefinition -> Text -> SortDefinition)
-> Lens SortDefinition SortDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortDefinition' {Text
key :: Text
$sel:key:SortDefinition' :: SortDefinition -> Text
key} -> Text
key) (\s :: SortDefinition
s@SortDefinition' {} Text
a -> SortDefinition
s {$sel:key:SortDefinition' :: Text
key = Text
a} :: SortDefinition)

instance Prelude.Hashable SortDefinition

instance Prelude.NFData SortDefinition

instance Core.ToJSON SortDefinition where
  toJSON :: SortDefinition -> Value
toJSON SortDefinition' {Maybe SortOrder
Text
key :: Text
sortOrder :: Maybe SortOrder
$sel:key:SortDefinition' :: SortDefinition -> Text
$sel:sortOrder:SortDefinition' :: SortDefinition -> 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,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key)
          ]
      )