{-# 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.Route53Domains.Types.SortCondition
-- 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.Route53Domains.Types.SortCondition where

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
import Amazonka.Route53Domains.Types.ListDomainsAttributeName
import Amazonka.Route53Domains.Types.SortOrder

-- | Information for sorting a list of domains.
--
-- /See:/ 'newSortCondition' smart constructor.
data SortCondition = SortCondition'
  { -- | Field to be used for sorting the list of domains. It can be either the
    -- name or the expiration for a domain. Note that if @filterCondition@ is
    -- used in the same
    -- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_domains__ListDomains.html ListDomains>
    -- call, the field used for sorting has to be the same as the field used
    -- for filtering.
    SortCondition -> ListDomainsAttributeName
name :: ListDomainsAttributeName,
    -- | The sort order for a list of domains. Either ascending (ASC) or
    -- descending (DES).
    SortCondition -> SortOrder
sortOrder :: SortOrder
  }
  deriving (SortCondition -> SortCondition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SortCondition -> SortCondition -> Bool
$c/= :: SortCondition -> SortCondition -> Bool
== :: SortCondition -> SortCondition -> Bool
$c== :: SortCondition -> SortCondition -> Bool
Prelude.Eq, ReadPrec [SortCondition]
ReadPrec SortCondition
Int -> ReadS SortCondition
ReadS [SortCondition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SortCondition]
$creadListPrec :: ReadPrec [SortCondition]
readPrec :: ReadPrec SortCondition
$creadPrec :: ReadPrec SortCondition
readList :: ReadS [SortCondition]
$creadList :: ReadS [SortCondition]
readsPrec :: Int -> ReadS SortCondition
$creadsPrec :: Int -> ReadS SortCondition
Prelude.Read, Int -> SortCondition -> ShowS
[SortCondition] -> ShowS
SortCondition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SortCondition] -> ShowS
$cshowList :: [SortCondition] -> ShowS
show :: SortCondition -> String
$cshow :: SortCondition -> String
showsPrec :: Int -> SortCondition -> ShowS
$cshowsPrec :: Int -> SortCondition -> ShowS
Prelude.Show, forall x. Rep SortCondition x -> SortCondition
forall x. SortCondition -> Rep SortCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SortCondition x -> SortCondition
$cfrom :: forall x. SortCondition -> Rep SortCondition x
Prelude.Generic)

-- |
-- Create a value of 'SortCondition' 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:
--
-- 'name', 'sortCondition_name' - Field to be used for sorting the list of domains. It can be either the
-- name or the expiration for a domain. Note that if @filterCondition@ is
-- used in the same
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_domains__ListDomains.html ListDomains>
-- call, the field used for sorting has to be the same as the field used
-- for filtering.
--
-- 'sortOrder', 'sortCondition_sortOrder' - The sort order for a list of domains. Either ascending (ASC) or
-- descending (DES).
newSortCondition ::
  -- | 'name'
  ListDomainsAttributeName ->
  -- | 'sortOrder'
  SortOrder ->
  SortCondition
newSortCondition :: ListDomainsAttributeName -> SortOrder -> SortCondition
newSortCondition ListDomainsAttributeName
pName_ SortOrder
pSortOrder_ =
  SortCondition'
    { $sel:name:SortCondition' :: ListDomainsAttributeName
name = ListDomainsAttributeName
pName_,
      $sel:sortOrder:SortCondition' :: SortOrder
sortOrder = SortOrder
pSortOrder_
    }

-- | Field to be used for sorting the list of domains. It can be either the
-- name or the expiration for a domain. Note that if @filterCondition@ is
-- used in the same
-- <https://docs.aws.amazon.com/Route53/latest/APIReference/API_domains__ListDomains.html ListDomains>
-- call, the field used for sorting has to be the same as the field used
-- for filtering.
sortCondition_name :: Lens.Lens' SortCondition ListDomainsAttributeName
sortCondition_name :: Lens' SortCondition ListDomainsAttributeName
sortCondition_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCondition' {ListDomainsAttributeName
name :: ListDomainsAttributeName
$sel:name:SortCondition' :: SortCondition -> ListDomainsAttributeName
name} -> ListDomainsAttributeName
name) (\s :: SortCondition
s@SortCondition' {} ListDomainsAttributeName
a -> SortCondition
s {$sel:name:SortCondition' :: ListDomainsAttributeName
name = ListDomainsAttributeName
a} :: SortCondition)

-- | The sort order for a list of domains. Either ascending (ASC) or
-- descending (DES).
sortCondition_sortOrder :: Lens.Lens' SortCondition SortOrder
sortCondition_sortOrder :: Lens' SortCondition SortOrder
sortCondition_sortOrder = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SortCondition' {SortOrder
sortOrder :: SortOrder
$sel:sortOrder:SortCondition' :: SortCondition -> SortOrder
sortOrder} -> SortOrder
sortOrder) (\s :: SortCondition
s@SortCondition' {} SortOrder
a -> SortCondition
s {$sel:sortOrder:SortCondition' :: SortOrder
sortOrder = SortOrder
a} :: SortCondition)

instance Prelude.Hashable SortCondition where
  hashWithSalt :: Int -> SortCondition -> Int
hashWithSalt Int
_salt SortCondition' {ListDomainsAttributeName
SortOrder
sortOrder :: SortOrder
name :: ListDomainsAttributeName
$sel:sortOrder:SortCondition' :: SortCondition -> SortOrder
$sel:name:SortCondition' :: SortCondition -> ListDomainsAttributeName
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ListDomainsAttributeName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SortOrder
sortOrder

instance Prelude.NFData SortCondition where
  rnf :: SortCondition -> ()
rnf SortCondition' {ListDomainsAttributeName
SortOrder
sortOrder :: SortOrder
name :: ListDomainsAttributeName
$sel:sortOrder:SortCondition' :: SortCondition -> SortOrder
$sel:name:SortCondition' :: SortCondition -> ListDomainsAttributeName
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ListDomainsAttributeName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SortOrder
sortOrder

instance Data.ToJSON SortCondition where
  toJSON :: SortCondition -> Value
toJSON SortCondition' {ListDomainsAttributeName
SortOrder
sortOrder :: SortOrder
name :: ListDomainsAttributeName
$sel:sortOrder:SortCondition' :: SortCondition -> SortOrder
$sel:name:SortCondition' :: SortCondition -> ListDomainsAttributeName
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ListDomainsAttributeName
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"SortOrder" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SortOrder
sortOrder)
          ]
      )