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

-- | Provides the details of a stored query.
--
-- /See:/ 'newStoredQuery' smart constructor.
data StoredQuery = StoredQuery'
  { -- | A unique description for the query.
    StoredQuery -> Maybe Text
description :: 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,
    -- | 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 ID of the query.
    StoredQuery -> Maybe Text
queryId :: Prelude.Maybe Prelude.Text,
    -- | The name of the query.
    StoredQuery -> Text
queryName :: Prelude.Text
  }
  deriving (StoredQuery -> StoredQuery -> Bool
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]
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
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. 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:
--
-- 'description', 'storedQuery_description' - A unique description for the query.
--
-- '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\'.@
--
-- 'queryArn', 'storedQuery_queryArn' - Amazon Resource Name (ARN) of the query. For example,
-- arn:partition:service:region:account-id:resource-type\/resource-name\/resource-id.
--
-- 'queryId', 'storedQuery_queryId' - The ID of the query.
--
-- 'queryName', 'storedQuery_queryName' - The name of the query.
newStoredQuery ::
  -- | 'queryName'
  Prelude.Text ->
  StoredQuery
newStoredQuery :: Text -> StoredQuery
newStoredQuery Text
pQueryName_ =
  StoredQuery'
    { $sel:description:StoredQuery' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:expression:StoredQuery' :: Maybe Text
expression = forall a. Maybe a
Prelude.Nothing,
      $sel:queryArn:StoredQuery' :: Maybe Text
queryArn = forall a. Maybe a
Prelude.Nothing,
      $sel:queryId:StoredQuery' :: Maybe Text
queryId = forall a. Maybe a
Prelude.Nothing,
      $sel:queryName:StoredQuery' :: Text
queryName = Text
pQueryName_
    }

-- | A unique description for the query.
storedQuery_description :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_description :: Lens' StoredQuery (Maybe Text)
storedQuery_description = 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 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 :: Lens' StoredQuery (Maybe Text)
storedQuery_expression = 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)

-- | 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 :: Lens' StoredQuery (Maybe Text)
storedQuery_queryArn = 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 ID of the query.
storedQuery_queryId :: Lens.Lens' StoredQuery (Prelude.Maybe Prelude.Text)
storedQuery_queryId :: Lens' StoredQuery (Maybe Text)
storedQuery_queryId = 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)

-- | The name of the query.
storedQuery_queryName :: Lens.Lens' StoredQuery Prelude.Text
storedQuery_queryName :: Lens' StoredQuery Text
storedQuery_queryName = 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 Data.FromJSON StoredQuery where
  parseJSON :: Value -> Parser StoredQuery
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StoredQuery"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> StoredQuery
StoredQuery'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Expression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"QueryArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"QueryId")
            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
"QueryName")
      )

instance Prelude.Hashable StoredQuery where
  hashWithSalt :: Int -> StoredQuery -> Int
hashWithSalt Int
_salt StoredQuery' {Maybe Text
Text
queryName :: Text
queryId :: Maybe Text
queryArn :: Maybe Text
expression :: Maybe Text
description :: Maybe Text
$sel:queryName:StoredQuery' :: StoredQuery -> Text
$sel:queryId:StoredQuery' :: StoredQuery -> Maybe Text
$sel:queryArn:StoredQuery' :: StoredQuery -> Maybe Text
$sel:expression:StoredQuery' :: StoredQuery -> Maybe Text
$sel:description:StoredQuery' :: StoredQuery -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
queryArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
queryId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
queryName

instance Prelude.NFData StoredQuery where
  rnf :: StoredQuery -> ()
rnf StoredQuery' {Maybe Text
Text
queryName :: Text
queryId :: Maybe Text
queryArn :: Maybe Text
expression :: Maybe Text
description :: Maybe Text
$sel:queryName:StoredQuery' :: StoredQuery -> Text
$sel:queryId:StoredQuery' :: StoredQuery -> Maybe Text
$sel:queryArn:StoredQuery' :: StoredQuery -> Maybe Text
$sel:expression:StoredQuery' :: StoredQuery -> Maybe Text
$sel:description:StoredQuery' :: StoredQuery -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
expression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
queryArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
queryId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
queryName

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