{-# 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.AmplifyUiBuilder.Types.SortProperty
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AmplifyUiBuilder.Types.SortProperty where

import Amazonka.AmplifyUiBuilder.Types.SortDirection
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes how to sort the data that you bind to a component.
--
-- /See:/ 'newSortProperty' smart constructor.
data SortProperty = SortProperty'
  { -- | The direction of the sort, either ascending or descending.
    SortProperty -> SortDirection
direction :: SortDirection,
    -- | The field to perform the sort on.
    SortProperty -> Text
field :: Prelude.Text
  }
  deriving (SortProperty -> SortProperty -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SortProperty -> SortProperty -> Bool
$c/= :: SortProperty -> SortProperty -> Bool
== :: SortProperty -> SortProperty -> Bool
$c== :: SortProperty -> SortProperty -> Bool
Prelude.Eq, ReadPrec [SortProperty]
ReadPrec SortProperty
Int -> ReadS SortProperty
ReadS [SortProperty]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SortProperty]
$creadListPrec :: ReadPrec [SortProperty]
readPrec :: ReadPrec SortProperty
$creadPrec :: ReadPrec SortProperty
readList :: ReadS [SortProperty]
$creadList :: ReadS [SortProperty]
readsPrec :: Int -> ReadS SortProperty
$creadsPrec :: Int -> ReadS SortProperty
Prelude.Read, Int -> SortProperty -> ShowS
[SortProperty] -> ShowS
SortProperty -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SortProperty] -> ShowS
$cshowList :: [SortProperty] -> ShowS
show :: SortProperty -> String
$cshow :: SortProperty -> String
showsPrec :: Int -> SortProperty -> ShowS
$cshowsPrec :: Int -> SortProperty -> ShowS
Prelude.Show, forall x. Rep SortProperty x -> SortProperty
forall x. SortProperty -> Rep SortProperty x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SortProperty x -> SortProperty
$cfrom :: forall x. SortProperty -> Rep SortProperty x
Prelude.Generic)

-- |
-- Create a value of 'SortProperty' 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:
--
-- 'direction', 'sortProperty_direction' - The direction of the sort, either ascending or descending.
--
-- 'field', 'sortProperty_field' - The field to perform the sort on.
newSortProperty ::
  -- | 'direction'
  SortDirection ->
  -- | 'field'
  Prelude.Text ->
  SortProperty
newSortProperty :: SortDirection -> Text -> SortProperty
newSortProperty SortDirection
pDirection_ Text
pField_ =
  SortProperty'
    { $sel:direction:SortProperty' :: SortDirection
direction = SortDirection
pDirection_,
      $sel:field:SortProperty' :: Text
field = Text
pField_
    }

-- | The direction of the sort, either ascending or descending.
sortProperty_direction :: Lens.Lens' SortProperty SortDirection
sortProperty_direction :: Lens' SortProperty SortDirection
sortProperty_direction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortProperty' {SortDirection
direction :: SortDirection
$sel:direction:SortProperty' :: SortProperty -> SortDirection
direction} -> SortDirection
direction) (\s :: SortProperty
s@SortProperty' {} SortDirection
a -> SortProperty
s {$sel:direction:SortProperty' :: SortDirection
direction = SortDirection
a} :: SortProperty)

-- | The field to perform the sort on.
sortProperty_field :: Lens.Lens' SortProperty Prelude.Text
sortProperty_field :: Lens' SortProperty Text
sortProperty_field = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortProperty' {Text
field :: Text
$sel:field:SortProperty' :: SortProperty -> Text
field} -> Text
field) (\s :: SortProperty
s@SortProperty' {} Text
a -> SortProperty
s {$sel:field:SortProperty' :: Text
field = Text
a} :: SortProperty)

instance Data.FromJSON SortProperty where
  parseJSON :: Value -> Parser SortProperty
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SortProperty"
      ( \Object
x ->
          SortDirection -> Text -> SortProperty
SortProperty'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"direction")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"field")
      )

instance Prelude.Hashable SortProperty where
  hashWithSalt :: Int -> SortProperty -> Int
hashWithSalt Int
_salt SortProperty' {Text
SortDirection
field :: Text
direction :: SortDirection
$sel:field:SortProperty' :: SortProperty -> Text
$sel:direction:SortProperty' :: SortProperty -> SortDirection
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SortDirection
direction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
field

instance Prelude.NFData SortProperty where
  rnf :: SortProperty -> ()
rnf SortProperty' {Text
SortDirection
field :: Text
direction :: SortDirection
$sel:field:SortProperty' :: SortProperty -> Text
$sel:direction:SortProperty' :: SortProperty -> SortDirection
..} =
    forall a. NFData a => a -> ()
Prelude.rnf SortDirection
direction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
field

instance Data.ToJSON SortProperty where
  toJSON :: SortProperty -> Value
toJSON SortProperty' {Text
SortDirection
field :: Text
direction :: SortDirection
$sel:field:SortProperty' :: SortProperty -> Text
$sel:direction:SortProperty' :: SortProperty -> SortDirection
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"direction" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SortDirection
direction),
            forall a. a -> Maybe a
Prelude.Just (Key
"field" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
field)
          ]
      )