{-# 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.Config.Types.StoredQuery
-- 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.Config.Types.StoredQuery where

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

-- | Provides the details of a stored query.
--
-- /See:/ 'newStoredQuery' smart constructor.
data StoredQuery = StoredQuery'
  { -- | The ID of the query.
    StoredQuery -> Maybe Text
queryId :: Prelude.Maybe Prelude.Text,
    -- | Amazon Resource Name (ARN) of the query. For example,
    -- arn:partition:service:region:account-id:resource-type\/resource-name\/resource-id.
    StoredQuery -> Maybe Text
queryArn :: Prelude.Maybe Prelude.Text,
    -- | The expression of the query. For example,
    -- @SELECT resourceId, resourceType, supplementaryConfiguration.BucketVersioningConfiguration.status WHERE resourceType = \'AWS::S3::Bucket\' AND supplementaryConfiguration.BucketVersioningConfiguration.status = \'Off\'.@
    StoredQuery -> Maybe Text
expression :: Prelude.Maybe Prelude.Text,
    -- | A unique description for the query.
    StoredQuery -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the query.
    StoredQuery -> Text
queryName :: Prelude.Text
  }
  deriving (StoredQuery -> StoredQuery -> Bool
(StoredQuery -> StoredQuery -> Bool)
-> (StoredQuery -> StoredQuery -> Bool) -> Eq StoredQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StoredQuery -> StoredQuery -> Bool
$c/= :: StoredQuery -> StoredQuery -> Bool
== :: StoredQuery -> StoredQuery -> Bool
$c== :: StoredQuery -> StoredQuery -> Bool
Prelude.Eq, ReadPrec [StoredQuery]
ReadPrec StoredQuery
Int -> ReadS StoredQuery
ReadS [StoredQuery]
(Int -> ReadS StoredQuery)
-> ReadS [StoredQuery]
-> ReadPrec StoredQuery
-> ReadPrec [StoredQuery]
-> Read StoredQuery
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StoredQuery]
$creadListPrec :: ReadPrec [StoredQuery]
readPrec :: ReadPrec StoredQuery
$creadPrec :: ReadPrec StoredQuery
readList :: ReadS [StoredQuery]
$creadList :: ReadS [StoredQuery]
readsPrec :: Int -> ReadS StoredQuery
$creadsPrec :: Int -> ReadS StoredQuery
Prelude.Read, Int -> StoredQuery -> ShowS
[StoredQuery] -> ShowS
StoredQuery -> String
(Int -> StoredQuery -> ShowS)
-> (StoredQuery -> String)
-> ([StoredQuery] -> ShowS)
-> Show StoredQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StoredQuery] -> ShowS
$cshowList :: [StoredQuery] -> ShowS
show :: StoredQuery -> String
$cshow :: StoredQuery -> String
showsPrec :: Int -> StoredQuery -> ShowS
$cshowsPrec :: Int -> StoredQuery -> ShowS
Prelude.Show, (forall x. StoredQuery -> Rep StoredQuery x)
-> (forall x. Rep StoredQuery x -> StoredQuery)
-> Generic StoredQuery
forall x. Rep StoredQuery x -> StoredQuery
forall x. StoredQuery -> Rep StoredQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StoredQuery x -> StoredQuery
$cfrom :: forall x. StoredQuery -> Rep StoredQuery x
Prelude.Generic)

-- |
-- Create a value of 'StoredQuery' 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:
--
-- 'queryId', 'storedQuery_queryId' - The ID of the query.
--
-- 'queryArn', 'storedQuery_queryArn' - Amazon Resource Name (ARN) of the query. For example,
-- arn:partition:service:region:account-id:resource-type\/resource-name\/resource-id.
--
-- 'expression', 'storedQuery_expression' - The expression of the query. For example,
-- @SELECT resourceId, resourceType, supplementaryConfiguration.BucketVersioningConfiguration.status WHERE resourceType = \'AWS::S3::Bucket\' AND supplementaryConfiguration.BucketVersioningConfiguration.status = \'Off\'.@
--
-- 'description', 'storedQuery_description' - A unique description for the query.
--
-- 'queryName', 'storedQuery_queryName' - The name of the query.
newStoredQuery ::
  -- | 'queryName'
  Prelude.Text ->
  StoredQuery
newStoredQuery :: Text -> StoredQuery
newStoredQuery Text
pQueryName_ =
  StoredQuery' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery
StoredQuery'
    { $sel:queryId:StoredQuery' :: Maybe Text
queryId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:queryArn:StoredQuery' :: Maybe Text
queryArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:expression:StoredQuery' :: Maybe Text
expression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:StoredQuery' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:queryName:StoredQuery' :: Text
queryName = Text
pQueryName_
    }

-- | The ID of the query.
storedQuery_queryId :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_queryId :: (Maybe Text -> f (Maybe Text)) -> StoredQuery -> f StoredQuery
storedQuery_queryId = (StoredQuery -> Maybe Text)
-> (StoredQuery -> Maybe Text -> StoredQuery)
-> Lens StoredQuery StoredQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StoredQuery' {Maybe Text
queryId :: Maybe Text
$sel:queryId:StoredQuery' :: StoredQuery -> Maybe Text
queryId} -> Maybe Text
queryId) (\s :: StoredQuery
s@StoredQuery' {} Maybe Text
a -> StoredQuery
s {$sel:queryId:StoredQuery' :: Maybe Text
queryId = Maybe Text
a} :: StoredQuery)

-- | Amazon Resource Name (ARN) of the query. For example,
-- arn:partition:service:region:account-id:resource-type\/resource-name\/resource-id.
storedQuery_queryArn :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_queryArn :: (Maybe Text -> f (Maybe Text)) -> StoredQuery -> f StoredQuery
storedQuery_queryArn = (StoredQuery -> Maybe Text)
-> (StoredQuery -> Maybe Text -> StoredQuery)
-> Lens StoredQuery StoredQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StoredQuery' {Maybe Text
queryArn :: Maybe Text
$sel:queryArn:StoredQuery' :: StoredQuery -> Maybe Text
queryArn} -> Maybe Text
queryArn) (\s :: StoredQuery
s@StoredQuery' {} Maybe Text
a -> StoredQuery
s {$sel:queryArn:StoredQuery' :: Maybe Text
queryArn = Maybe Text
a} :: StoredQuery)

-- | The expression of the query. For example,
-- @SELECT resourceId, resourceType, supplementaryConfiguration.BucketVersioningConfiguration.status WHERE resourceType = \'AWS::S3::Bucket\' AND supplementaryConfiguration.BucketVersioningConfiguration.status = \'Off\'.@
storedQuery_expression :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_expression :: (Maybe Text -> f (Maybe Text)) -> StoredQuery -> f StoredQuery
storedQuery_expression = (StoredQuery -> Maybe Text)
-> (StoredQuery -> Maybe Text -> StoredQuery)
-> Lens StoredQuery StoredQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StoredQuery' {Maybe Text
expression :: Maybe Text
$sel:expression:StoredQuery' :: StoredQuery -> Maybe Text
expression} -> Maybe Text
expression) (\s :: StoredQuery
s@StoredQuery' {} Maybe Text
a -> StoredQuery
s {$sel:expression:StoredQuery' :: Maybe Text
expression = Maybe Text
a} :: StoredQuery)

-- | A unique description for the query.
storedQuery_description :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_description :: (Maybe Text -> f (Maybe Text)) -> StoredQuery -> f StoredQuery
storedQuery_description = (StoredQuery -> Maybe Text)
-> (StoredQuery -> Maybe Text -> StoredQuery)
-> Lens StoredQuery StoredQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StoredQuery' {Maybe Text
description :: Maybe Text
$sel:description:StoredQuery' :: StoredQuery -> Maybe Text
description} -> Maybe Text
description) (\s :: StoredQuery
s@StoredQuery' {} Maybe Text
a -> StoredQuery
s {$sel:description:StoredQuery' :: Maybe Text
description = Maybe Text
a} :: StoredQuery)

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

instance Core.FromJSON StoredQuery where
  parseJSON :: Value -> Parser StoredQuery
parseJSON =
    String
-> (Object -> Parser StoredQuery) -> Value -> Parser StoredQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StoredQuery"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery
StoredQuery'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"QueryId")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Text -> StoredQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"QueryArn")
            Parser (Maybe Text -> Maybe Text -> Text -> StoredQuery)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Text -> StoredQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Expression")
            Parser (Maybe Text -> Text -> StoredQuery)
-> Parser (Maybe Text) -> Parser (Text -> StoredQuery)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Description")
            Parser (Text -> StoredQuery) -> Parser Text -> Parser StoredQuery
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"QueryName")
      )

instance Prelude.Hashable StoredQuery

instance Prelude.NFData StoredQuery

instance Core.ToJSON StoredQuery where
  toJSON :: StoredQuery -> Value
toJSON StoredQuery' {Maybe Text
Text
queryName :: Text
description :: Maybe Text
expression :: Maybe Text
queryArn :: Maybe Text
queryId :: Maybe Text
$sel:queryName:StoredQuery' :: StoredQuery -> Text
$sel:description:StoredQuery' :: StoredQuery -> Maybe Text
$sel:expression:StoredQuery' :: StoredQuery -> Maybe Text
$sel:queryArn:StoredQuery' :: StoredQuery -> Maybe Text
$sel:queryId:StoredQuery' :: StoredQuery -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"QueryId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
queryId,
            (Text
"QueryArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
queryArn,
            (Text
"Expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
expression,
            (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"QueryName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
queryName)
          ]
      )