{-# 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.ResultConfiguration
-- 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.ResultConfiguration where

import Amazonka.Athena.Types.EncryptionConfiguration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The location in Amazon S3 where query results are stored and the
-- encryption option, if any, used for query results. These are known as
-- \"client-side settings\". If workgroup settings override client-side
-- settings, then the query uses the workgroup settings.
--
-- /See:/ 'newResultConfiguration' smart constructor.
data ResultConfiguration = ResultConfiguration'
  { -- | If query results are encrypted in Amazon S3, indicates the encryption
    -- option used (for example, @SSE-KMS@ or @CSE-KMS@) and key information.
    -- This is a client-side setting. If workgroup settings override
    -- client-side settings, then the query uses the encryption configuration
    -- that is specified for the workgroup, and also uses the location for
    -- storing query results specified in the workgroup. See
    -- WorkGroupConfiguration$EnforceWorkGroupConfiguration and
    -- <https://docs.aws.amazon.com/athena/latest/ug/workgroups-settings-override.html Workgroup Settings Override Client-Side Settings>.
    ResultConfiguration -> Maybe EncryptionConfiguration
encryptionConfiguration :: Prelude.Maybe EncryptionConfiguration,
    -- | The location in Amazon S3 where your query results are stored, such as
    -- @s3:\/\/path\/to\/query\/bucket\/@. To run the query, you must specify
    -- the query results location using one of the ways: either for individual
    -- queries using either this setting (client-side), or in the workgroup,
    -- using WorkGroupConfiguration. If none of them is set, Athena issues an
    -- error that no output location is provided. For more information, see
    -- <https://docs.aws.amazon.com/athena/latest/ug/querying.html Query Results>.
    -- If workgroup settings override client-side settings, then the query uses
    -- the settings specified for the workgroup. See
    -- WorkGroupConfiguration$EnforceWorkGroupConfiguration.
    ResultConfiguration -> Maybe Text
outputLocation :: Prelude.Maybe Prelude.Text
  }
  deriving (ResultConfiguration -> ResultConfiguration -> Bool
(ResultConfiguration -> ResultConfiguration -> Bool)
-> (ResultConfiguration -> ResultConfiguration -> Bool)
-> Eq ResultConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultConfiguration -> ResultConfiguration -> Bool
$c/= :: ResultConfiguration -> ResultConfiguration -> Bool
== :: ResultConfiguration -> ResultConfiguration -> Bool
$c== :: ResultConfiguration -> ResultConfiguration -> Bool
Prelude.Eq, ReadPrec [ResultConfiguration]
ReadPrec ResultConfiguration
Int -> ReadS ResultConfiguration
ReadS [ResultConfiguration]
(Int -> ReadS ResultConfiguration)
-> ReadS [ResultConfiguration]
-> ReadPrec ResultConfiguration
-> ReadPrec [ResultConfiguration]
-> Read ResultConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResultConfiguration]
$creadListPrec :: ReadPrec [ResultConfiguration]
readPrec :: ReadPrec ResultConfiguration
$creadPrec :: ReadPrec ResultConfiguration
readList :: ReadS [ResultConfiguration]
$creadList :: ReadS [ResultConfiguration]
readsPrec :: Int -> ReadS ResultConfiguration
$creadsPrec :: Int -> ReadS ResultConfiguration
Prelude.Read, Int -> ResultConfiguration -> ShowS
[ResultConfiguration] -> ShowS
ResultConfiguration -> String
(Int -> ResultConfiguration -> ShowS)
-> (ResultConfiguration -> String)
-> ([ResultConfiguration] -> ShowS)
-> Show ResultConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultConfiguration] -> ShowS
$cshowList :: [ResultConfiguration] -> ShowS
show :: ResultConfiguration -> String
$cshow :: ResultConfiguration -> String
showsPrec :: Int -> ResultConfiguration -> ShowS
$cshowsPrec :: Int -> ResultConfiguration -> ShowS
Prelude.Show, (forall x. ResultConfiguration -> Rep ResultConfiguration x)
-> (forall x. Rep ResultConfiguration x -> ResultConfiguration)
-> Generic ResultConfiguration
forall x. Rep ResultConfiguration x -> ResultConfiguration
forall x. ResultConfiguration -> Rep ResultConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResultConfiguration x -> ResultConfiguration
$cfrom :: forall x. ResultConfiguration -> Rep ResultConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ResultConfiguration' 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:
--
-- 'encryptionConfiguration', 'resultConfiguration_encryptionConfiguration' - If query results are encrypted in Amazon S3, indicates the encryption
-- option used (for example, @SSE-KMS@ or @CSE-KMS@) and key information.
-- This is a client-side setting. If workgroup settings override
-- client-side settings, then the query uses the encryption configuration
-- that is specified for the workgroup, and also uses the location for
-- storing query results specified in the workgroup. See
-- WorkGroupConfiguration$EnforceWorkGroupConfiguration and
-- <https://docs.aws.amazon.com/athena/latest/ug/workgroups-settings-override.html Workgroup Settings Override Client-Side Settings>.
--
-- 'outputLocation', 'resultConfiguration_outputLocation' - The location in Amazon S3 where your query results are stored, such as
-- @s3:\/\/path\/to\/query\/bucket\/@. To run the query, you must specify
-- the query results location using one of the ways: either for individual
-- queries using either this setting (client-side), or in the workgroup,
-- using WorkGroupConfiguration. If none of them is set, Athena issues an
-- error that no output location is provided. For more information, see
-- <https://docs.aws.amazon.com/athena/latest/ug/querying.html Query Results>.
-- If workgroup settings override client-side settings, then the query uses
-- the settings specified for the workgroup. See
-- WorkGroupConfiguration$EnforceWorkGroupConfiguration.
newResultConfiguration ::
  ResultConfiguration
newResultConfiguration :: ResultConfiguration
newResultConfiguration =
  ResultConfiguration' :: Maybe EncryptionConfiguration -> Maybe Text -> ResultConfiguration
ResultConfiguration'
    { $sel:encryptionConfiguration:ResultConfiguration' :: Maybe EncryptionConfiguration
encryptionConfiguration =
        Maybe EncryptionConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:outputLocation:ResultConfiguration' :: Maybe Text
outputLocation = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | If query results are encrypted in Amazon S3, indicates the encryption
-- option used (for example, @SSE-KMS@ or @CSE-KMS@) and key information.
-- This is a client-side setting. If workgroup settings override
-- client-side settings, then the query uses the encryption configuration
-- that is specified for the workgroup, and also uses the location for
-- storing query results specified in the workgroup. See
-- WorkGroupConfiguration$EnforceWorkGroupConfiguration and
-- <https://docs.aws.amazon.com/athena/latest/ug/workgroups-settings-override.html Workgroup Settings Override Client-Side Settings>.
resultConfiguration_encryptionConfiguration :: Lens.Lens' ResultConfiguration (Prelude.Maybe EncryptionConfiguration)
resultConfiguration_encryptionConfiguration :: (Maybe EncryptionConfiguration
 -> f (Maybe EncryptionConfiguration))
-> ResultConfiguration -> f ResultConfiguration
resultConfiguration_encryptionConfiguration = (ResultConfiguration -> Maybe EncryptionConfiguration)
-> (ResultConfiguration
    -> Maybe EncryptionConfiguration -> ResultConfiguration)
-> Lens
     ResultConfiguration
     ResultConfiguration
     (Maybe EncryptionConfiguration)
     (Maybe EncryptionConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultConfiguration' {Maybe EncryptionConfiguration
encryptionConfiguration :: Maybe EncryptionConfiguration
$sel:encryptionConfiguration:ResultConfiguration' :: ResultConfiguration -> Maybe EncryptionConfiguration
encryptionConfiguration} -> Maybe EncryptionConfiguration
encryptionConfiguration) (\s :: ResultConfiguration
s@ResultConfiguration' {} Maybe EncryptionConfiguration
a -> ResultConfiguration
s {$sel:encryptionConfiguration:ResultConfiguration' :: Maybe EncryptionConfiguration
encryptionConfiguration = Maybe EncryptionConfiguration
a} :: ResultConfiguration)

-- | The location in Amazon S3 where your query results are stored, such as
-- @s3:\/\/path\/to\/query\/bucket\/@. To run the query, you must specify
-- the query results location using one of the ways: either for individual
-- queries using either this setting (client-side), or in the workgroup,
-- using WorkGroupConfiguration. If none of them is set, Athena issues an
-- error that no output location is provided. For more information, see
-- <https://docs.aws.amazon.com/athena/latest/ug/querying.html Query Results>.
-- If workgroup settings override client-side settings, then the query uses
-- the settings specified for the workgroup. See
-- WorkGroupConfiguration$EnforceWorkGroupConfiguration.
resultConfiguration_outputLocation :: Lens.Lens' ResultConfiguration (Prelude.Maybe Prelude.Text)
resultConfiguration_outputLocation :: (Maybe Text -> f (Maybe Text))
-> ResultConfiguration -> f ResultConfiguration
resultConfiguration_outputLocation = (ResultConfiguration -> Maybe Text)
-> (ResultConfiguration -> Maybe Text -> ResultConfiguration)
-> Lens
     ResultConfiguration ResultConfiguration (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultConfiguration' {Maybe Text
outputLocation :: Maybe Text
$sel:outputLocation:ResultConfiguration' :: ResultConfiguration -> Maybe Text
outputLocation} -> Maybe Text
outputLocation) (\s :: ResultConfiguration
s@ResultConfiguration' {} Maybe Text
a -> ResultConfiguration
s {$sel:outputLocation:ResultConfiguration' :: Maybe Text
outputLocation = Maybe Text
a} :: ResultConfiguration)

instance Core.FromJSON ResultConfiguration where
  parseJSON :: Value -> Parser ResultConfiguration
parseJSON =
    String
-> (Object -> Parser ResultConfiguration)
-> Value
-> Parser ResultConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResultConfiguration"
      ( \Object
x ->
          Maybe EncryptionConfiguration -> Maybe Text -> ResultConfiguration
ResultConfiguration'
            (Maybe EncryptionConfiguration
 -> Maybe Text -> ResultConfiguration)
-> Parser (Maybe EncryptionConfiguration)
-> Parser (Maybe Text -> ResultConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EncryptionConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EncryptionConfiguration")
            Parser (Maybe Text -> ResultConfiguration)
-> Parser (Maybe Text) -> Parser ResultConfiguration
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
"OutputLocation")
      )

instance Prelude.Hashable ResultConfiguration

instance Prelude.NFData ResultConfiguration

instance Core.ToJSON ResultConfiguration where
  toJSON :: ResultConfiguration -> Value
toJSON ResultConfiguration' {Maybe Text
Maybe EncryptionConfiguration
outputLocation :: Maybe Text
encryptionConfiguration :: Maybe EncryptionConfiguration
$sel:outputLocation:ResultConfiguration' :: ResultConfiguration -> Maybe Text
$sel:encryptionConfiguration:ResultConfiguration' :: ResultConfiguration -> Maybe EncryptionConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EncryptionConfiguration" Text -> EncryptionConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (EncryptionConfiguration -> Pair)
-> Maybe EncryptionConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EncryptionConfiguration
encryptionConfiguration,
            (Text
"OutputLocation" 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
outputLocation
          ]
      )