{-# 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.Athena.Types.NamedQuery
-- 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.Athena.Types.NamedQuery where

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

-- | A query, where @QueryString@ is the list of SQL query statements that
-- comprise the query.
--
-- /See:/ 'newNamedQuery' smart constructor.
data NamedQuery = NamedQuery'
  { -- | The unique identifier of the query.
    NamedQuery -> Maybe Text
namedQueryId :: Prelude.Maybe Prelude.Text,
    -- | The query description.
    NamedQuery -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the workgroup that contains the named query.
    NamedQuery -> Maybe Text
workGroup :: Prelude.Maybe Prelude.Text,
    -- | The query name.
    NamedQuery -> Text
name :: Prelude.Text,
    -- | The database to which the query belongs.
    NamedQuery -> Text
database :: Prelude.Text,
    -- | The SQL query statements that comprise the query.
    NamedQuery -> Text
queryString :: Prelude.Text
  }
  deriving (NamedQuery -> NamedQuery -> Bool
(NamedQuery -> NamedQuery -> Bool)
-> (NamedQuery -> NamedQuery -> Bool) -> Eq NamedQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NamedQuery -> NamedQuery -> Bool
$c/= :: NamedQuery -> NamedQuery -> Bool
== :: NamedQuery -> NamedQuery -> Bool
$c== :: NamedQuery -> NamedQuery -> Bool
Prelude.Eq, ReadPrec [NamedQuery]
ReadPrec NamedQuery
Int -> ReadS NamedQuery
ReadS [NamedQuery]
(Int -> ReadS NamedQuery)
-> ReadS [NamedQuery]
-> ReadPrec NamedQuery
-> ReadPrec [NamedQuery]
-> Read NamedQuery
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NamedQuery]
$creadListPrec :: ReadPrec [NamedQuery]
readPrec :: ReadPrec NamedQuery
$creadPrec :: ReadPrec NamedQuery
readList :: ReadS [NamedQuery]
$creadList :: ReadS [NamedQuery]
readsPrec :: Int -> ReadS NamedQuery
$creadsPrec :: Int -> ReadS NamedQuery
Prelude.Read, Int -> NamedQuery -> ShowS
[NamedQuery] -> ShowS
NamedQuery -> String
(Int -> NamedQuery -> ShowS)
-> (NamedQuery -> String)
-> ([NamedQuery] -> ShowS)
-> Show NamedQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NamedQuery] -> ShowS
$cshowList :: [NamedQuery] -> ShowS
show :: NamedQuery -> String
$cshow :: NamedQuery -> String
showsPrec :: Int -> NamedQuery -> ShowS
$cshowsPrec :: Int -> NamedQuery -> ShowS
Prelude.Show, (forall x. NamedQuery -> Rep NamedQuery x)
-> (forall x. Rep NamedQuery x -> NamedQuery) -> Generic NamedQuery
forall x. Rep NamedQuery x -> NamedQuery
forall x. NamedQuery -> Rep NamedQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NamedQuery x -> NamedQuery
$cfrom :: forall x. NamedQuery -> Rep NamedQuery x
Prelude.Generic)

-- |
-- Create a value of 'NamedQuery' 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:
--
-- 'namedQueryId', 'namedQuery_namedQueryId' - The unique identifier of the query.
--
-- 'description', 'namedQuery_description' - The query description.
--
-- 'workGroup', 'namedQuery_workGroup' - The name of the workgroup that contains the named query.
--
-- 'name', 'namedQuery_name' - The query name.
--
-- 'database', 'namedQuery_database' - The database to which the query belongs.
--
-- 'queryString', 'namedQuery_queryString' - The SQL query statements that comprise the query.
newNamedQuery ::
  -- | 'name'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'queryString'
  Prelude.Text ->
  NamedQuery
newNamedQuery :: Text -> Text -> Text -> NamedQuery
newNamedQuery Text
pName_ Text
pDatabase_ Text
pQueryString_ =
  NamedQuery' :: Maybe Text
-> Maybe Text -> Maybe Text -> Text -> Text -> Text -> NamedQuery
NamedQuery'
    { $sel:namedQueryId:NamedQuery' :: Maybe Text
namedQueryId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:NamedQuery' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:workGroup:NamedQuery' :: Maybe Text
workGroup = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:NamedQuery' :: Text
name = Text
pName_,
      $sel:database:NamedQuery' :: Text
database = Text
pDatabase_,
      $sel:queryString:NamedQuery' :: Text
queryString = Text
pQueryString_
    }

-- | The unique identifier of the query.
namedQuery_namedQueryId :: Lens.Lens' NamedQuery (Prelude.Maybe Prelude.Text)
namedQuery_namedQueryId :: (Maybe Text -> f (Maybe Text)) -> NamedQuery -> f NamedQuery
namedQuery_namedQueryId = (NamedQuery -> Maybe Text)
-> (NamedQuery -> Maybe Text -> NamedQuery)
-> Lens NamedQuery NamedQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NamedQuery' {Maybe Text
namedQueryId :: Maybe Text
$sel:namedQueryId:NamedQuery' :: NamedQuery -> Maybe Text
namedQueryId} -> Maybe Text
namedQueryId) (\s :: NamedQuery
s@NamedQuery' {} Maybe Text
a -> NamedQuery
s {$sel:namedQueryId:NamedQuery' :: Maybe Text
namedQueryId = Maybe Text
a} :: NamedQuery)

-- | The query description.
namedQuery_description :: Lens.Lens' NamedQuery (Prelude.Maybe Prelude.Text)
namedQuery_description :: (Maybe Text -> f (Maybe Text)) -> NamedQuery -> f NamedQuery
namedQuery_description = (NamedQuery -> Maybe Text)
-> (NamedQuery -> Maybe Text -> NamedQuery)
-> Lens NamedQuery NamedQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NamedQuery' {Maybe Text
description :: Maybe Text
$sel:description:NamedQuery' :: NamedQuery -> Maybe Text
description} -> Maybe Text
description) (\s :: NamedQuery
s@NamedQuery' {} Maybe Text
a -> NamedQuery
s {$sel:description:NamedQuery' :: Maybe Text
description = Maybe Text
a} :: NamedQuery)

-- | The name of the workgroup that contains the named query.
namedQuery_workGroup :: Lens.Lens' NamedQuery (Prelude.Maybe Prelude.Text)
namedQuery_workGroup :: (Maybe Text -> f (Maybe Text)) -> NamedQuery -> f NamedQuery
namedQuery_workGroup = (NamedQuery -> Maybe Text)
-> (NamedQuery -> Maybe Text -> NamedQuery)
-> Lens NamedQuery NamedQuery (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NamedQuery' {Maybe Text
workGroup :: Maybe Text
$sel:workGroup:NamedQuery' :: NamedQuery -> Maybe Text
workGroup} -> Maybe Text
workGroup) (\s :: NamedQuery
s@NamedQuery' {} Maybe Text
a -> NamedQuery
s {$sel:workGroup:NamedQuery' :: Maybe Text
workGroup = Maybe Text
a} :: NamedQuery)

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

-- | The database to which the query belongs.
namedQuery_database :: Lens.Lens' NamedQuery Prelude.Text
namedQuery_database :: (Text -> f Text) -> NamedQuery -> f NamedQuery
namedQuery_database = (NamedQuery -> Text)
-> (NamedQuery -> Text -> NamedQuery)
-> Lens NamedQuery NamedQuery Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NamedQuery' {Text
database :: Text
$sel:database:NamedQuery' :: NamedQuery -> Text
database} -> Text
database) (\s :: NamedQuery
s@NamedQuery' {} Text
a -> NamedQuery
s {$sel:database:NamedQuery' :: Text
database = Text
a} :: NamedQuery)

-- | The SQL query statements that comprise the query.
namedQuery_queryString :: Lens.Lens' NamedQuery Prelude.Text
namedQuery_queryString :: (Text -> f Text) -> NamedQuery -> f NamedQuery
namedQuery_queryString = (NamedQuery -> Text)
-> (NamedQuery -> Text -> NamedQuery)
-> Lens NamedQuery NamedQuery Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NamedQuery' {Text
queryString :: Text
$sel:queryString:NamedQuery' :: NamedQuery -> Text
queryString} -> Text
queryString) (\s :: NamedQuery
s@NamedQuery' {} Text
a -> NamedQuery
s {$sel:queryString:NamedQuery' :: Text
queryString = Text
a} :: NamedQuery)

instance Core.FromJSON NamedQuery where
  parseJSON :: Value -> Parser NamedQuery
parseJSON =
    String
-> (Object -> Parser NamedQuery) -> Value -> Parser NamedQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NamedQuery"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Text -> Text -> Text -> NamedQuery
NamedQuery'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Text -> Text -> Text -> NamedQuery)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Text -> Text -> Text -> NamedQuery)
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
"NamedQueryId")
            Parser
  (Maybe Text -> Maybe Text -> Text -> Text -> Text -> NamedQuery)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Text -> Text -> Text -> NamedQuery)
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 (Maybe Text -> Text -> Text -> Text -> NamedQuery)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> Text -> NamedQuery)
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
"WorkGroup")
            Parser (Text -> Text -> Text -> NamedQuery)
-> Parser Text -> Parser (Text -> Text -> NamedQuery)
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
"Name")
            Parser (Text -> Text -> NamedQuery)
-> Parser Text -> Parser (Text -> NamedQuery)
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
"Database")
            Parser (Text -> NamedQuery) -> Parser Text -> Parser NamedQuery
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
"QueryString")
      )

instance Prelude.Hashable NamedQuery

instance Prelude.NFData NamedQuery