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

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.ContainerDatasetAction
import Amazonka.IoTAnalytics.Types.SqlQueryDatasetAction
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A @DatasetAction@ object that specifies how dataset contents are
-- automatically created.
--
-- /See:/ 'newDatasetAction' smart constructor.
data DatasetAction = DatasetAction'
  { -- | An @SqlQueryDatasetAction@ object that uses an SQL query to
    -- automatically create dataset contents.
    DatasetAction -> Maybe SqlQueryDatasetAction
queryAction :: Prelude.Maybe SqlQueryDatasetAction,
    -- | The name of the dataset action by which dataset contents are
    -- automatically created.
    DatasetAction -> Maybe Text
actionName :: Prelude.Maybe Prelude.Text,
    -- | Information that allows the system to run a containerized application to
    -- create the dataset contents. The application must be in a Docker
    -- container along with any required support libraries.
    DatasetAction -> Maybe ContainerDatasetAction
containerAction :: Prelude.Maybe ContainerDatasetAction
  }
  deriving (DatasetAction -> DatasetAction -> Bool
(DatasetAction -> DatasetAction -> Bool)
-> (DatasetAction -> DatasetAction -> Bool) -> Eq DatasetAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DatasetAction -> DatasetAction -> Bool
$c/= :: DatasetAction -> DatasetAction -> Bool
== :: DatasetAction -> DatasetAction -> Bool
$c== :: DatasetAction -> DatasetAction -> Bool
Prelude.Eq, ReadPrec [DatasetAction]
ReadPrec DatasetAction
Int -> ReadS DatasetAction
ReadS [DatasetAction]
(Int -> ReadS DatasetAction)
-> ReadS [DatasetAction]
-> ReadPrec DatasetAction
-> ReadPrec [DatasetAction]
-> Read DatasetAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DatasetAction]
$creadListPrec :: ReadPrec [DatasetAction]
readPrec :: ReadPrec DatasetAction
$creadPrec :: ReadPrec DatasetAction
readList :: ReadS [DatasetAction]
$creadList :: ReadS [DatasetAction]
readsPrec :: Int -> ReadS DatasetAction
$creadsPrec :: Int -> ReadS DatasetAction
Prelude.Read, Int -> DatasetAction -> ShowS
[DatasetAction] -> ShowS
DatasetAction -> String
(Int -> DatasetAction -> ShowS)
-> (DatasetAction -> String)
-> ([DatasetAction] -> ShowS)
-> Show DatasetAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DatasetAction] -> ShowS
$cshowList :: [DatasetAction] -> ShowS
show :: DatasetAction -> String
$cshow :: DatasetAction -> String
showsPrec :: Int -> DatasetAction -> ShowS
$cshowsPrec :: Int -> DatasetAction -> ShowS
Prelude.Show, (forall x. DatasetAction -> Rep DatasetAction x)
-> (forall x. Rep DatasetAction x -> DatasetAction)
-> Generic DatasetAction
forall x. Rep DatasetAction x -> DatasetAction
forall x. DatasetAction -> Rep DatasetAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DatasetAction x -> DatasetAction
$cfrom :: forall x. DatasetAction -> Rep DatasetAction x
Prelude.Generic)

-- |
-- Create a value of 'DatasetAction' 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:
--
-- 'queryAction', 'datasetAction_queryAction' - An @SqlQueryDatasetAction@ object that uses an SQL query to
-- automatically create dataset contents.
--
-- 'actionName', 'datasetAction_actionName' - The name of the dataset action by which dataset contents are
-- automatically created.
--
-- 'containerAction', 'datasetAction_containerAction' - Information that allows the system to run a containerized application to
-- create the dataset contents. The application must be in a Docker
-- container along with any required support libraries.
newDatasetAction ::
  DatasetAction
newDatasetAction :: DatasetAction
newDatasetAction =
  DatasetAction' :: Maybe SqlQueryDatasetAction
-> Maybe Text -> Maybe ContainerDatasetAction -> DatasetAction
DatasetAction'
    { $sel:queryAction:DatasetAction' :: Maybe SqlQueryDatasetAction
queryAction = Maybe SqlQueryDatasetAction
forall a. Maybe a
Prelude.Nothing,
      $sel:actionName:DatasetAction' :: Maybe Text
actionName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:containerAction:DatasetAction' :: Maybe ContainerDatasetAction
containerAction = Maybe ContainerDatasetAction
forall a. Maybe a
Prelude.Nothing
    }

-- | An @SqlQueryDatasetAction@ object that uses an SQL query to
-- automatically create dataset contents.
datasetAction_queryAction :: Lens.Lens' DatasetAction (Prelude.Maybe SqlQueryDatasetAction)
datasetAction_queryAction :: (Maybe SqlQueryDatasetAction -> f (Maybe SqlQueryDatasetAction))
-> DatasetAction -> f DatasetAction
datasetAction_queryAction = (DatasetAction -> Maybe SqlQueryDatasetAction)
-> (DatasetAction -> Maybe SqlQueryDatasetAction -> DatasetAction)
-> Lens
     DatasetAction
     DatasetAction
     (Maybe SqlQueryDatasetAction)
     (Maybe SqlQueryDatasetAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatasetAction' {Maybe SqlQueryDatasetAction
queryAction :: Maybe SqlQueryDatasetAction
$sel:queryAction:DatasetAction' :: DatasetAction -> Maybe SqlQueryDatasetAction
queryAction} -> Maybe SqlQueryDatasetAction
queryAction) (\s :: DatasetAction
s@DatasetAction' {} Maybe SqlQueryDatasetAction
a -> DatasetAction
s {$sel:queryAction:DatasetAction' :: Maybe SqlQueryDatasetAction
queryAction = Maybe SqlQueryDatasetAction
a} :: DatasetAction)

-- | The name of the dataset action by which dataset contents are
-- automatically created.
datasetAction_actionName :: Lens.Lens' DatasetAction (Prelude.Maybe Prelude.Text)
datasetAction_actionName :: (Maybe Text -> f (Maybe Text)) -> DatasetAction -> f DatasetAction
datasetAction_actionName = (DatasetAction -> Maybe Text)
-> (DatasetAction -> Maybe Text -> DatasetAction)
-> Lens DatasetAction DatasetAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatasetAction' {Maybe Text
actionName :: Maybe Text
$sel:actionName:DatasetAction' :: DatasetAction -> Maybe Text
actionName} -> Maybe Text
actionName) (\s :: DatasetAction
s@DatasetAction' {} Maybe Text
a -> DatasetAction
s {$sel:actionName:DatasetAction' :: Maybe Text
actionName = Maybe Text
a} :: DatasetAction)

-- | Information that allows the system to run a containerized application to
-- create the dataset contents. The application must be in a Docker
-- container along with any required support libraries.
datasetAction_containerAction :: Lens.Lens' DatasetAction (Prelude.Maybe ContainerDatasetAction)
datasetAction_containerAction :: (Maybe ContainerDatasetAction -> f (Maybe ContainerDatasetAction))
-> DatasetAction -> f DatasetAction
datasetAction_containerAction = (DatasetAction -> Maybe ContainerDatasetAction)
-> (DatasetAction -> Maybe ContainerDatasetAction -> DatasetAction)
-> Lens
     DatasetAction
     DatasetAction
     (Maybe ContainerDatasetAction)
     (Maybe ContainerDatasetAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatasetAction' {Maybe ContainerDatasetAction
containerAction :: Maybe ContainerDatasetAction
$sel:containerAction:DatasetAction' :: DatasetAction -> Maybe ContainerDatasetAction
containerAction} -> Maybe ContainerDatasetAction
containerAction) (\s :: DatasetAction
s@DatasetAction' {} Maybe ContainerDatasetAction
a -> DatasetAction
s {$sel:containerAction:DatasetAction' :: Maybe ContainerDatasetAction
containerAction = Maybe ContainerDatasetAction
a} :: DatasetAction)

instance Core.FromJSON DatasetAction where
  parseJSON :: Value -> Parser DatasetAction
parseJSON =
    String
-> (Object -> Parser DatasetAction)
-> Value
-> Parser DatasetAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DatasetAction"
      ( \Object
x ->
          Maybe SqlQueryDatasetAction
-> Maybe Text -> Maybe ContainerDatasetAction -> DatasetAction
DatasetAction'
            (Maybe SqlQueryDatasetAction
 -> Maybe Text -> Maybe ContainerDatasetAction -> DatasetAction)
-> Parser (Maybe SqlQueryDatasetAction)
-> Parser
     (Maybe Text -> Maybe ContainerDatasetAction -> DatasetAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe SqlQueryDatasetAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"queryAction")
            Parser
  (Maybe Text -> Maybe ContainerDatasetAction -> DatasetAction)
-> Parser (Maybe Text)
-> Parser (Maybe ContainerDatasetAction -> DatasetAction)
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
"actionName")
            Parser (Maybe ContainerDatasetAction -> DatasetAction)
-> Parser (Maybe ContainerDatasetAction) -> Parser DatasetAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ContainerDatasetAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"containerAction")
      )

instance Prelude.Hashable DatasetAction

instance Prelude.NFData DatasetAction

instance Core.ToJSON DatasetAction where
  toJSON :: DatasetAction -> Value
toJSON DatasetAction' {Maybe Text
Maybe SqlQueryDatasetAction
Maybe ContainerDatasetAction
containerAction :: Maybe ContainerDatasetAction
actionName :: Maybe Text
queryAction :: Maybe SqlQueryDatasetAction
$sel:containerAction:DatasetAction' :: DatasetAction -> Maybe ContainerDatasetAction
$sel:actionName:DatasetAction' :: DatasetAction -> Maybe Text
$sel:queryAction:DatasetAction' :: DatasetAction -> Maybe SqlQueryDatasetAction
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"queryAction" Text -> SqlQueryDatasetAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SqlQueryDatasetAction -> Pair)
-> Maybe SqlQueryDatasetAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SqlQueryDatasetAction
queryAction,
            (Text
"actionName" 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
actionName,
            (Text
"containerAction" Text -> ContainerDatasetAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ContainerDatasetAction -> Pair)
-> Maybe ContainerDatasetAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ContainerDatasetAction
containerAction
          ]
      )