{-# 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.IoTAnalytics.Types.SqlQueryDatasetAction
-- 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.IoTAnalytics.Types.SqlQueryDatasetAction where

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.QueryFilter
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The SQL query to modify the message.
--
-- /See:/ 'newSqlQueryDatasetAction' smart constructor.
data SqlQueryDatasetAction = SqlQueryDatasetAction'
  { -- | Prefilters applied to message data.
    SqlQueryDatasetAction -> Maybe [QueryFilter]
filters :: Prelude.Maybe [QueryFilter],
    -- | A SQL query string.
    SqlQueryDatasetAction -> Text
sqlQuery :: Prelude.Text
  }
  deriving (SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool
(SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool)
-> (SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool)
-> Eq SqlQueryDatasetAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool
$c/= :: SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool
== :: SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool
$c== :: SqlQueryDatasetAction -> SqlQueryDatasetAction -> Bool
Prelude.Eq, ReadPrec [SqlQueryDatasetAction]
ReadPrec SqlQueryDatasetAction
Int -> ReadS SqlQueryDatasetAction
ReadS [SqlQueryDatasetAction]
(Int -> ReadS SqlQueryDatasetAction)
-> ReadS [SqlQueryDatasetAction]
-> ReadPrec SqlQueryDatasetAction
-> ReadPrec [SqlQueryDatasetAction]
-> Read SqlQueryDatasetAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SqlQueryDatasetAction]
$creadListPrec :: ReadPrec [SqlQueryDatasetAction]
readPrec :: ReadPrec SqlQueryDatasetAction
$creadPrec :: ReadPrec SqlQueryDatasetAction
readList :: ReadS [SqlQueryDatasetAction]
$creadList :: ReadS [SqlQueryDatasetAction]
readsPrec :: Int -> ReadS SqlQueryDatasetAction
$creadsPrec :: Int -> ReadS SqlQueryDatasetAction
Prelude.Read, Int -> SqlQueryDatasetAction -> ShowS
[SqlQueryDatasetAction] -> ShowS
SqlQueryDatasetAction -> String
(Int -> SqlQueryDatasetAction -> ShowS)
-> (SqlQueryDatasetAction -> String)
-> ([SqlQueryDatasetAction] -> ShowS)
-> Show SqlQueryDatasetAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqlQueryDatasetAction] -> ShowS
$cshowList :: [SqlQueryDatasetAction] -> ShowS
show :: SqlQueryDatasetAction -> String
$cshow :: SqlQueryDatasetAction -> String
showsPrec :: Int -> SqlQueryDatasetAction -> ShowS
$cshowsPrec :: Int -> SqlQueryDatasetAction -> ShowS
Prelude.Show, (forall x. SqlQueryDatasetAction -> Rep SqlQueryDatasetAction x)
-> (forall x. Rep SqlQueryDatasetAction x -> SqlQueryDatasetAction)
-> Generic SqlQueryDatasetAction
forall x. Rep SqlQueryDatasetAction x -> SqlQueryDatasetAction
forall x. SqlQueryDatasetAction -> Rep SqlQueryDatasetAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SqlQueryDatasetAction x -> SqlQueryDatasetAction
$cfrom :: forall x. SqlQueryDatasetAction -> Rep SqlQueryDatasetAction x
Prelude.Generic)

-- |
-- Create a value of 'SqlQueryDatasetAction' 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:
--
-- 'filters', 'sqlQueryDatasetAction_filters' - Prefilters applied to message data.
--
-- 'sqlQuery', 'sqlQueryDatasetAction_sqlQuery' - A SQL query string.
newSqlQueryDatasetAction ::
  -- | 'sqlQuery'
  Prelude.Text ->
  SqlQueryDatasetAction
newSqlQueryDatasetAction :: Text -> SqlQueryDatasetAction
newSqlQueryDatasetAction Text
pSqlQuery_ =
  SqlQueryDatasetAction' :: Maybe [QueryFilter] -> Text -> SqlQueryDatasetAction
SqlQueryDatasetAction'
    { $sel:filters:SqlQueryDatasetAction' :: Maybe [QueryFilter]
filters = Maybe [QueryFilter]
forall a. Maybe a
Prelude.Nothing,
      $sel:sqlQuery:SqlQueryDatasetAction' :: Text
sqlQuery = Text
pSqlQuery_
    }

-- | Prefilters applied to message data.
sqlQueryDatasetAction_filters :: Lens.Lens' SqlQueryDatasetAction (Prelude.Maybe [QueryFilter])
sqlQueryDatasetAction_filters :: (Maybe [QueryFilter] -> f (Maybe [QueryFilter]))
-> SqlQueryDatasetAction -> f SqlQueryDatasetAction
sqlQueryDatasetAction_filters = (SqlQueryDatasetAction -> Maybe [QueryFilter])
-> (SqlQueryDatasetAction
    -> Maybe [QueryFilter] -> SqlQueryDatasetAction)
-> Lens
     SqlQueryDatasetAction
     SqlQueryDatasetAction
     (Maybe [QueryFilter])
     (Maybe [QueryFilter])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqlQueryDatasetAction' {Maybe [QueryFilter]
filters :: Maybe [QueryFilter]
$sel:filters:SqlQueryDatasetAction' :: SqlQueryDatasetAction -> Maybe [QueryFilter]
filters} -> Maybe [QueryFilter]
filters) (\s :: SqlQueryDatasetAction
s@SqlQueryDatasetAction' {} Maybe [QueryFilter]
a -> SqlQueryDatasetAction
s {$sel:filters:SqlQueryDatasetAction' :: Maybe [QueryFilter]
filters = Maybe [QueryFilter]
a} :: SqlQueryDatasetAction) ((Maybe [QueryFilter] -> f (Maybe [QueryFilter]))
 -> SqlQueryDatasetAction -> f SqlQueryDatasetAction)
-> ((Maybe [QueryFilter] -> f (Maybe [QueryFilter]))
    -> Maybe [QueryFilter] -> f (Maybe [QueryFilter]))
-> (Maybe [QueryFilter] -> f (Maybe [QueryFilter]))
-> SqlQueryDatasetAction
-> f SqlQueryDatasetAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [QueryFilter] [QueryFilter] [QueryFilter] [QueryFilter]
-> Iso
     (Maybe [QueryFilter])
     (Maybe [QueryFilter])
     (Maybe [QueryFilter])
     (Maybe [QueryFilter])
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 [QueryFilter] [QueryFilter] [QueryFilter] [QueryFilter]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A SQL query string.
sqlQueryDatasetAction_sqlQuery :: Lens.Lens' SqlQueryDatasetAction Prelude.Text
sqlQueryDatasetAction_sqlQuery :: (Text -> f Text)
-> SqlQueryDatasetAction -> f SqlQueryDatasetAction
sqlQueryDatasetAction_sqlQuery = (SqlQueryDatasetAction -> Text)
-> (SqlQueryDatasetAction -> Text -> SqlQueryDatasetAction)
-> Lens SqlQueryDatasetAction SqlQueryDatasetAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SqlQueryDatasetAction' {Text
sqlQuery :: Text
$sel:sqlQuery:SqlQueryDatasetAction' :: SqlQueryDatasetAction -> Text
sqlQuery} -> Text
sqlQuery) (\s :: SqlQueryDatasetAction
s@SqlQueryDatasetAction' {} Text
a -> SqlQueryDatasetAction
s {$sel:sqlQuery:SqlQueryDatasetAction' :: Text
sqlQuery = Text
a} :: SqlQueryDatasetAction)

instance Core.FromJSON SqlQueryDatasetAction where
  parseJSON :: Value -> Parser SqlQueryDatasetAction
parseJSON =
    String
-> (Object -> Parser SqlQueryDatasetAction)
-> Value
-> Parser SqlQueryDatasetAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SqlQueryDatasetAction"
      ( \Object
x ->
          Maybe [QueryFilter] -> Text -> SqlQueryDatasetAction
SqlQueryDatasetAction'
            (Maybe [QueryFilter] -> Text -> SqlQueryDatasetAction)
-> Parser (Maybe [QueryFilter])
-> Parser (Text -> SqlQueryDatasetAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [QueryFilter]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"filters" Parser (Maybe (Maybe [QueryFilter]))
-> Maybe [QueryFilter] -> Parser (Maybe [QueryFilter])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [QueryFilter]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> SqlQueryDatasetAction)
-> Parser Text -> Parser SqlQueryDatasetAction
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
"sqlQuery")
      )

instance Prelude.Hashable SqlQueryDatasetAction

instance Prelude.NFData SqlQueryDatasetAction

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