{-# 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.Glue.Types.Order
-- 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.Glue.Types.Order where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies the sort order of a sorted column.
--
-- /See:/ 'newOrder' smart constructor.
data Order = Order'
  { -- | The name of the column.
    Order -> Text
column :: Prelude.Text,
    -- | Indicates that the column is sorted in ascending order (@== 1@), or in
    -- descending order (@==0@).
    Order -> Natural
sortOrder :: Prelude.Natural
  }
  deriving (Order -> Order -> Bool
(Order -> Order -> Bool) -> (Order -> Order -> Bool) -> Eq Order
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Order -> Order -> Bool
$c/= :: Order -> Order -> Bool
== :: Order -> Order -> Bool
$c== :: Order -> Order -> Bool
Prelude.Eq, ReadPrec [Order]
ReadPrec Order
Int -> ReadS Order
ReadS [Order]
(Int -> ReadS Order)
-> ReadS [Order]
-> ReadPrec Order
-> ReadPrec [Order]
-> Read Order
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Order]
$creadListPrec :: ReadPrec [Order]
readPrec :: ReadPrec Order
$creadPrec :: ReadPrec Order
readList :: ReadS [Order]
$creadList :: ReadS [Order]
readsPrec :: Int -> ReadS Order
$creadsPrec :: Int -> ReadS Order
Prelude.Read, Int -> Order -> ShowS
[Order] -> ShowS
Order -> String
(Int -> Order -> ShowS)
-> (Order -> String) -> ([Order] -> ShowS) -> Show Order
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Order] -> ShowS
$cshowList :: [Order] -> ShowS
show :: Order -> String
$cshow :: Order -> String
showsPrec :: Int -> Order -> ShowS
$cshowsPrec :: Int -> Order -> ShowS
Prelude.Show, (forall x. Order -> Rep Order x)
-> (forall x. Rep Order x -> Order) -> Generic Order
forall x. Rep Order x -> Order
forall x. Order -> Rep Order x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Order x -> Order
$cfrom :: forall x. Order -> Rep Order x
Prelude.Generic)

-- |
-- Create a value of 'Order' 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:
--
-- 'column', 'order_column' - The name of the column.
--
-- 'sortOrder', 'order_sortOrder' - Indicates that the column is sorted in ascending order (@== 1@), or in
-- descending order (@==0@).
newOrder ::
  -- | 'column'
  Prelude.Text ->
  -- | 'sortOrder'
  Prelude.Natural ->
  Order
newOrder :: Text -> Natural -> Order
newOrder Text
pColumn_ Natural
pSortOrder_ =
  Order' :: Text -> Natural -> Order
Order' {$sel:column:Order' :: Text
column = Text
pColumn_, $sel:sortOrder:Order' :: Natural
sortOrder = Natural
pSortOrder_}

-- | The name of the column.
order_column :: Lens.Lens' Order Prelude.Text
order_column :: (Text -> f Text) -> Order -> f Order
order_column = (Order -> Text)
-> (Order -> Text -> Order) -> Lens Order Order Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Order' {Text
column :: Text
$sel:column:Order' :: Order -> Text
column} -> Text
column) (\s :: Order
s@Order' {} Text
a -> Order
s {$sel:column:Order' :: Text
column = Text
a} :: Order)

-- | Indicates that the column is sorted in ascending order (@== 1@), or in
-- descending order (@==0@).
order_sortOrder :: Lens.Lens' Order Prelude.Natural
order_sortOrder :: (Natural -> f Natural) -> Order -> f Order
order_sortOrder = (Order -> Natural)
-> (Order -> Natural -> Order) -> Lens Order Order Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Order' {Natural
sortOrder :: Natural
$sel:sortOrder:Order' :: Order -> Natural
sortOrder} -> Natural
sortOrder) (\s :: Order
s@Order' {} Natural
a -> Order
s {$sel:sortOrder:Order' :: Natural
sortOrder = Natural
a} :: Order)

instance Core.FromJSON Order where
  parseJSON :: Value -> Parser Order
parseJSON =
    String -> (Object -> Parser Order) -> Value -> Parser Order
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Order"
      ( \Object
x ->
          Text -> Natural -> Order
Order'
            (Text -> Natural -> Order)
-> Parser Text -> Parser (Natural -> Order)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Column")
            Parser (Natural -> Order) -> Parser Natural -> Parser Order
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SortOrder")
      )

instance Prelude.Hashable Order

instance Prelude.NFData Order

instance Core.ToJSON Order where
  toJSON :: Order -> Value
toJSON Order' {Natural
Text
sortOrder :: Natural
column :: Text
$sel:sortOrder:Order' :: Order -> Natural
$sel:column:Order' :: Order -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Column" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
column),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"SortOrder" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
sortOrder)
          ]
      )