{-# 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.DataPipeline.Types.Query
-- 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.DataPipeline.Types.Query where

import qualified Amazonka.Core as Core
import Amazonka.DataPipeline.Types.Selector
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Defines the query to run against an object.
--
-- /See:/ 'newQuery' smart constructor.
data Query = Query'
  { -- | List of selectors that define the query. An object must satisfy all of
    -- the selectors to match the query.
    Query -> Maybe [Selector]
selectors :: Prelude.Maybe [Selector]
  }
  deriving (Query -> Query -> Bool
(Query -> Query -> Bool) -> (Query -> Query -> Bool) -> Eq Query
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Query -> Query -> Bool
$c/= :: Query -> Query -> Bool
== :: Query -> Query -> Bool
$c== :: Query -> Query -> Bool
Prelude.Eq, ReadPrec [Query]
ReadPrec Query
Int -> ReadS Query
ReadS [Query]
(Int -> ReadS Query)
-> ReadS [Query]
-> ReadPrec Query
-> ReadPrec [Query]
-> Read Query
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Query]
$creadListPrec :: ReadPrec [Query]
readPrec :: ReadPrec Query
$creadPrec :: ReadPrec Query
readList :: ReadS [Query]
$creadList :: ReadS [Query]
readsPrec :: Int -> ReadS Query
$creadsPrec :: Int -> ReadS Query
Prelude.Read, Int -> Query -> ShowS
[Query] -> ShowS
Query -> String
(Int -> Query -> ShowS)
-> (Query -> String) -> ([Query] -> ShowS) -> Show Query
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Query] -> ShowS
$cshowList :: [Query] -> ShowS
show :: Query -> String
$cshow :: Query -> String
showsPrec :: Int -> Query -> ShowS
$cshowsPrec :: Int -> Query -> ShowS
Prelude.Show, (forall x. Query -> Rep Query x)
-> (forall x. Rep Query x -> Query) -> Generic Query
forall x. Rep Query x -> Query
forall x. Query -> Rep Query x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Query x -> Query
$cfrom :: forall x. Query -> Rep Query x
Prelude.Generic)

-- |
-- Create a value of 'Query' 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:
--
-- 'selectors', 'query_selectors' - List of selectors that define the query. An object must satisfy all of
-- the selectors to match the query.
newQuery ::
  Query
newQuery :: Query
newQuery = Query' :: Maybe [Selector] -> Query
Query' {$sel:selectors:Query' :: Maybe [Selector]
selectors = Maybe [Selector]
forall a. Maybe a
Prelude.Nothing}

-- | List of selectors that define the query. An object must satisfy all of
-- the selectors to match the query.
query_selectors :: Lens.Lens' Query (Prelude.Maybe [Selector])
query_selectors :: (Maybe [Selector] -> f (Maybe [Selector])) -> Query -> f Query
query_selectors = (Query -> Maybe [Selector])
-> (Query -> Maybe [Selector] -> Query)
-> Lens Query Query (Maybe [Selector]) (Maybe [Selector])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe [Selector]
selectors :: Maybe [Selector]
$sel:selectors:Query' :: Query -> Maybe [Selector]
selectors} -> Maybe [Selector]
selectors) (\s :: Query
s@Query' {} Maybe [Selector]
a -> Query
s {$sel:selectors:Query' :: Maybe [Selector]
selectors = Maybe [Selector]
a} :: Query) ((Maybe [Selector] -> f (Maybe [Selector])) -> Query -> f Query)
-> ((Maybe [Selector] -> f (Maybe [Selector]))
    -> Maybe [Selector] -> f (Maybe [Selector]))
-> (Maybe [Selector] -> f (Maybe [Selector]))
-> Query
-> f Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Selector] [Selector] [Selector] [Selector]
-> Iso
     (Maybe [Selector])
     (Maybe [Selector])
     (Maybe [Selector])
     (Maybe [Selector])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Selector] [Selector] [Selector] [Selector]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable Query

instance Prelude.NFData Query

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