{-# 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.AppFlow.Types.Task
-- 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.AppFlow.Types.Task where

import Amazonka.AppFlow.Types.ConnectorOperator
import Amazonka.AppFlow.Types.OperatorPropertiesKeys
import Amazonka.AppFlow.Types.TaskType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A class for modeling different type of tasks. Task implementation varies
-- based on the @TaskType@.
--
-- /See:/ 'newTask' smart constructor.
data Task = Task'
  { -- | A map used to store task-related information. The execution service
    -- looks for particular information based on the @TaskType@.
    Task -> Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties :: Prelude.Maybe (Prelude.HashMap OperatorPropertiesKeys Prelude.Text),
    -- | The operation to be performed on the provided source fields.
    Task -> Maybe ConnectorOperator
connectorOperator :: Prelude.Maybe ConnectorOperator,
    -- | A field in a destination connector, or a field value against which
    -- Amazon AppFlow validates a source field.
    Task -> Maybe Text
destinationField :: Prelude.Maybe Prelude.Text,
    -- | The source fields to which a particular task is applied.
    Task -> [Text]
sourceFields :: [Prelude.Text],
    -- | Specifies the particular task implementation that Amazon AppFlow
    -- performs.
    Task -> TaskType
taskType :: TaskType
  }
  deriving (Task -> Task -> Bool
(Task -> Task -> Bool) -> (Task -> Task -> Bool) -> Eq Task
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Task -> Task -> Bool
$c/= :: Task -> Task -> Bool
== :: Task -> Task -> Bool
$c== :: Task -> Task -> Bool
Prelude.Eq, ReadPrec [Task]
ReadPrec Task
Int -> ReadS Task
ReadS [Task]
(Int -> ReadS Task)
-> ReadS [Task] -> ReadPrec Task -> ReadPrec [Task] -> Read Task
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Task]
$creadListPrec :: ReadPrec [Task]
readPrec :: ReadPrec Task
$creadPrec :: ReadPrec Task
readList :: ReadS [Task]
$creadList :: ReadS [Task]
readsPrec :: Int -> ReadS Task
$creadsPrec :: Int -> ReadS Task
Prelude.Read, Int -> Task -> ShowS
[Task] -> ShowS
Task -> String
(Int -> Task -> ShowS)
-> (Task -> String) -> ([Task] -> ShowS) -> Show Task
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Task] -> ShowS
$cshowList :: [Task] -> ShowS
show :: Task -> String
$cshow :: Task -> String
showsPrec :: Int -> Task -> ShowS
$cshowsPrec :: Int -> Task -> ShowS
Prelude.Show, (forall x. Task -> Rep Task x)
-> (forall x. Rep Task x -> Task) -> Generic Task
forall x. Rep Task x -> Task
forall x. Task -> Rep Task x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Task x -> Task
$cfrom :: forall x. Task -> Rep Task x
Prelude.Generic)

-- |
-- Create a value of 'Task' 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:
--
-- 'taskProperties', 'task_taskProperties' - A map used to store task-related information. The execution service
-- looks for particular information based on the @TaskType@.
--
-- 'connectorOperator', 'task_connectorOperator' - The operation to be performed on the provided source fields.
--
-- 'destinationField', 'task_destinationField' - A field in a destination connector, or a field value against which
-- Amazon AppFlow validates a source field.
--
-- 'sourceFields', 'task_sourceFields' - The source fields to which a particular task is applied.
--
-- 'taskType', 'task_taskType' - Specifies the particular task implementation that Amazon AppFlow
-- performs.
newTask ::
  -- | 'taskType'
  TaskType ->
  Task
newTask :: TaskType -> Task
newTask TaskType
pTaskType_ =
  Task' :: Maybe (HashMap OperatorPropertiesKeys Text)
-> Maybe ConnectorOperator
-> Maybe Text
-> [Text]
-> TaskType
-> Task
Task'
    { $sel:taskProperties:Task' :: Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties = Maybe (HashMap OperatorPropertiesKeys Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:connectorOperator:Task' :: Maybe ConnectorOperator
connectorOperator = Maybe ConnectorOperator
forall a. Maybe a
Prelude.Nothing,
      $sel:destinationField:Task' :: Maybe Text
destinationField = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceFields:Task' :: [Text]
sourceFields = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:taskType:Task' :: TaskType
taskType = TaskType
pTaskType_
    }

-- | A map used to store task-related information. The execution service
-- looks for particular information based on the @TaskType@.
task_taskProperties :: Lens.Lens' Task (Prelude.Maybe (Prelude.HashMap OperatorPropertiesKeys Prelude.Text))
task_taskProperties :: (Maybe (HashMap OperatorPropertiesKeys Text)
 -> f (Maybe (HashMap OperatorPropertiesKeys Text)))
-> Task -> f Task
task_taskProperties = (Task -> Maybe (HashMap OperatorPropertiesKeys Text))
-> (Task -> Maybe (HashMap OperatorPropertiesKeys Text) -> Task)
-> Lens
     Task
     Task
     (Maybe (HashMap OperatorPropertiesKeys Text))
     (Maybe (HashMap OperatorPropertiesKeys Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Task' {Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties :: Maybe (HashMap OperatorPropertiesKeys Text)
$sel:taskProperties:Task' :: Task -> Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties} -> Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties) (\s :: Task
s@Task' {} Maybe (HashMap OperatorPropertiesKeys Text)
a -> Task
s {$sel:taskProperties:Task' :: Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties = Maybe (HashMap OperatorPropertiesKeys Text)
a} :: Task) ((Maybe (HashMap OperatorPropertiesKeys Text)
  -> f (Maybe (HashMap OperatorPropertiesKeys Text)))
 -> Task -> f Task)
-> ((Maybe (HashMap OperatorPropertiesKeys Text)
     -> f (Maybe (HashMap OperatorPropertiesKeys Text)))
    -> Maybe (HashMap OperatorPropertiesKeys Text)
    -> f (Maybe (HashMap OperatorPropertiesKeys Text)))
-> (Maybe (HashMap OperatorPropertiesKeys Text)
    -> f (Maybe (HashMap OperatorPropertiesKeys Text)))
-> Task
-> f Task
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
-> Iso
     (Maybe (HashMap OperatorPropertiesKeys Text))
     (Maybe (HashMap OperatorPropertiesKeys Text))
     (Maybe (HashMap OperatorPropertiesKeys Text))
     (Maybe (HashMap OperatorPropertiesKeys Text))
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
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
  (HashMap OperatorPropertiesKeys Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The operation to be performed on the provided source fields.
task_connectorOperator :: Lens.Lens' Task (Prelude.Maybe ConnectorOperator)
task_connectorOperator :: (Maybe ConnectorOperator -> f (Maybe ConnectorOperator))
-> Task -> f Task
task_connectorOperator = (Task -> Maybe ConnectorOperator)
-> (Task -> Maybe ConnectorOperator -> Task)
-> Lens
     Task Task (Maybe ConnectorOperator) (Maybe ConnectorOperator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Task' {Maybe ConnectorOperator
connectorOperator :: Maybe ConnectorOperator
$sel:connectorOperator:Task' :: Task -> Maybe ConnectorOperator
connectorOperator} -> Maybe ConnectorOperator
connectorOperator) (\s :: Task
s@Task' {} Maybe ConnectorOperator
a -> Task
s {$sel:connectorOperator:Task' :: Maybe ConnectorOperator
connectorOperator = Maybe ConnectorOperator
a} :: Task)

-- | A field in a destination connector, or a field value against which
-- Amazon AppFlow validates a source field.
task_destinationField :: Lens.Lens' Task (Prelude.Maybe Prelude.Text)
task_destinationField :: (Maybe Text -> f (Maybe Text)) -> Task -> f Task
task_destinationField = (Task -> Maybe Text)
-> (Task -> Maybe Text -> Task)
-> Lens Task Task (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Task' {Maybe Text
destinationField :: Maybe Text
$sel:destinationField:Task' :: Task -> Maybe Text
destinationField} -> Maybe Text
destinationField) (\s :: Task
s@Task' {} Maybe Text
a -> Task
s {$sel:destinationField:Task' :: Maybe Text
destinationField = Maybe Text
a} :: Task)

-- | The source fields to which a particular task is applied.
task_sourceFields :: Lens.Lens' Task [Prelude.Text]
task_sourceFields :: ([Text] -> f [Text]) -> Task -> f Task
task_sourceFields = (Task -> [Text])
-> (Task -> [Text] -> Task) -> Lens Task Task [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Task' {[Text]
sourceFields :: [Text]
$sel:sourceFields:Task' :: Task -> [Text]
sourceFields} -> [Text]
sourceFields) (\s :: Task
s@Task' {} [Text]
a -> Task
s {$sel:sourceFields:Task' :: [Text]
sourceFields = [Text]
a} :: Task) (([Text] -> f [Text]) -> Task -> f Task)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> Task
-> f Task
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the particular task implementation that Amazon AppFlow
-- performs.
task_taskType :: Lens.Lens' Task TaskType
task_taskType :: (TaskType -> f TaskType) -> Task -> f Task
task_taskType = (Task -> TaskType)
-> (Task -> TaskType -> Task) -> Lens Task Task TaskType TaskType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Task' {TaskType
taskType :: TaskType
$sel:taskType:Task' :: Task -> TaskType
taskType} -> TaskType
taskType) (\s :: Task
s@Task' {} TaskType
a -> Task
s {$sel:taskType:Task' :: TaskType
taskType = TaskType
a} :: Task)

instance Core.FromJSON Task where
  parseJSON :: Value -> Parser Task
parseJSON =
    String -> (Object -> Parser Task) -> Value -> Parser Task
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Task"
      ( \Object
x ->
          Maybe (HashMap OperatorPropertiesKeys Text)
-> Maybe ConnectorOperator
-> Maybe Text
-> [Text]
-> TaskType
-> Task
Task'
            (Maybe (HashMap OperatorPropertiesKeys Text)
 -> Maybe ConnectorOperator
 -> Maybe Text
 -> [Text]
 -> TaskType
 -> Task)
-> Parser (Maybe (HashMap OperatorPropertiesKeys Text))
-> Parser
     (Maybe ConnectorOperator
      -> Maybe Text -> [Text] -> TaskType -> Task)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text
-> Parser (Maybe (Maybe (HashMap OperatorPropertiesKeys Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"taskProperties" Parser (Maybe (Maybe (HashMap OperatorPropertiesKeys Text)))
-> Maybe (HashMap OperatorPropertiesKeys Text)
-> Parser (Maybe (HashMap OperatorPropertiesKeys Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap OperatorPropertiesKeys Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe ConnectorOperator
   -> Maybe Text -> [Text] -> TaskType -> Task)
-> Parser (Maybe ConnectorOperator)
-> Parser (Maybe Text -> [Text] -> TaskType -> Task)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ConnectorOperator)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"connectorOperator")
            Parser (Maybe Text -> [Text] -> TaskType -> Task)
-> Parser (Maybe Text) -> Parser ([Text] -> TaskType -> Task)
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
"destinationField")
            Parser ([Text] -> TaskType -> Task)
-> Parser [Text] -> Parser (TaskType -> Task)
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
"sourceFields" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (TaskType -> Task) -> Parser TaskType -> Parser Task
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser TaskType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"taskType")
      )

instance Prelude.Hashable Task

instance Prelude.NFData Task

instance Core.ToJSON Task where
  toJSON :: Task -> Value
toJSON Task' {[Text]
Maybe Text
Maybe (HashMap OperatorPropertiesKeys Text)
Maybe ConnectorOperator
TaskType
taskType :: TaskType
sourceFields :: [Text]
destinationField :: Maybe Text
connectorOperator :: Maybe ConnectorOperator
taskProperties :: Maybe (HashMap OperatorPropertiesKeys Text)
$sel:taskType:Task' :: Task -> TaskType
$sel:sourceFields:Task' :: Task -> [Text]
$sel:destinationField:Task' :: Task -> Maybe Text
$sel:connectorOperator:Task' :: Task -> Maybe ConnectorOperator
$sel:taskProperties:Task' :: Task -> Maybe (HashMap OperatorPropertiesKeys Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"taskProperties" Text -> HashMap OperatorPropertiesKeys Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap OperatorPropertiesKeys Text -> Pair)
-> Maybe (HashMap OperatorPropertiesKeys Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap OperatorPropertiesKeys Text)
taskProperties,
            (Text
"connectorOperator" Text -> ConnectorOperator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ConnectorOperator -> Pair)
-> Maybe ConnectorOperator -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ConnectorOperator
connectorOperator,
            (Text
"destinationField" 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
destinationField,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"sourceFields" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
sourceFields),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"taskType" Text -> TaskType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TaskType
taskType)
          ]
      )