{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.StepFunctions.CreateActivity
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates an activity. An activity is a task that you write in any
-- programming language and host on any machine that has access to Step
-- Functions. Activities must poll Step Functions using the
-- @GetActivityTask@ API action and respond using @SendTask*@ API actions.
-- This function lets Step Functions know the existence of your activity
-- and returns an identifier for use in a state machine and when polling
-- from the activity.
--
-- This operation is eventually consistent. The results are best effort and
-- may not reflect very recent updates and changes.
--
-- @CreateActivity@ is an idempotent API. Subsequent requests won’t create
-- a duplicate resource if it was already created. @CreateActivity@\'s
-- idempotency check is based on the activity @name@. If a following
-- request has different @tags@ values, Step Functions will ignore these
-- differences and treat it as an idempotent request of the previous. In
-- this case, @tags@ will not be updated, even if they are different.
module Amazonka.StepFunctions.CreateActivity
  ( -- * Creating a Request
    CreateActivity (..),
    newCreateActivity,

    -- * Request Lenses
    createActivity_tags,
    createActivity_name,

    -- * Destructuring the Response
    CreateActivityResponse (..),
    newCreateActivityResponse,

    -- * Response Lenses
    createActivityResponse_httpStatus,
    createActivityResponse_activityArn,
    createActivityResponse_creationDate,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.StepFunctions.Types

-- | /See:/ 'newCreateActivity' smart constructor.
data CreateActivity = CreateActivity'
  { -- | The list of tags to add to a resource.
    --
    -- An array of key-value pairs. For more information, see
    -- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html Using Cost Allocation Tags>
    -- in the /Amazon Web Services Billing and Cost Management User Guide/, and
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_iam-tags.html Controlling Access Using IAM Tags>.
    --
    -- Tags may only contain Unicode letters, digits, white space, or these
    -- symbols: @_ . : \/ = + - \@@.
    CreateActivity -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the activity to create. This name must be unique for your
    -- Amazon Web Services account and region for 90 days. For more
    -- information, see
    -- <https://docs.aws.amazon.com/step-functions/latest/dg/limits.html#service-limits-state-machine-executions Limits Related to State Machine Executions>
    -- in the /Step Functions Developer Guide/.
    --
    -- A name must /not/ contain:
    --
    -- -   white space
    --
    -- -   brackets @\< > { } [ ]@
    --
    -- -   wildcard characters @? *@
    --
    -- -   special characters @\" # % \\ ^ | ~ \` $ & , ; : \/@
    --
    -- -   control characters (@U+0000-001F@, @U+007F-009F@)
    --
    -- To enable logging with CloudWatch Logs, the name should only contain
    -- 0-9, A-Z, a-z, - and _.
    CreateActivity -> Text
name :: Prelude.Text
  }
  deriving (CreateActivity -> CreateActivity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateActivity -> CreateActivity -> Bool
$c/= :: CreateActivity -> CreateActivity -> Bool
== :: CreateActivity -> CreateActivity -> Bool
$c== :: CreateActivity -> CreateActivity -> Bool
Prelude.Eq, ReadPrec [CreateActivity]
ReadPrec CreateActivity
Int -> ReadS CreateActivity
ReadS [CreateActivity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateActivity]
$creadListPrec :: ReadPrec [CreateActivity]
readPrec :: ReadPrec CreateActivity
$creadPrec :: ReadPrec CreateActivity
readList :: ReadS [CreateActivity]
$creadList :: ReadS [CreateActivity]
readsPrec :: Int -> ReadS CreateActivity
$creadsPrec :: Int -> ReadS CreateActivity
Prelude.Read, Int -> CreateActivity -> ShowS
[CreateActivity] -> ShowS
CreateActivity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateActivity] -> ShowS
$cshowList :: [CreateActivity] -> ShowS
show :: CreateActivity -> String
$cshow :: CreateActivity -> String
showsPrec :: Int -> CreateActivity -> ShowS
$cshowsPrec :: Int -> CreateActivity -> ShowS
Prelude.Show, forall x. Rep CreateActivity x -> CreateActivity
forall x. CreateActivity -> Rep CreateActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateActivity x -> CreateActivity
$cfrom :: forall x. CreateActivity -> Rep CreateActivity x
Prelude.Generic)

-- |
-- Create a value of 'CreateActivity' 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:
--
-- 'tags', 'createActivity_tags' - The list of tags to add to a resource.
--
-- An array of key-value pairs. For more information, see
-- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html Using Cost Allocation Tags>
-- in the /Amazon Web Services Billing and Cost Management User Guide/, and
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_iam-tags.html Controlling Access Using IAM Tags>.
--
-- Tags may only contain Unicode letters, digits, white space, or these
-- symbols: @_ . : \/ = + - \@@.
--
-- 'name', 'createActivity_name' - The name of the activity to create. This name must be unique for your
-- Amazon Web Services account and region for 90 days. For more
-- information, see
-- <https://docs.aws.amazon.com/step-functions/latest/dg/limits.html#service-limits-state-machine-executions Limits Related to State Machine Executions>
-- in the /Step Functions Developer Guide/.
--
-- A name must /not/ contain:
--
-- -   white space
--
-- -   brackets @\< > { } [ ]@
--
-- -   wildcard characters @? *@
--
-- -   special characters @\" # % \\ ^ | ~ \` $ & , ; : \/@
--
-- -   control characters (@U+0000-001F@, @U+007F-009F@)
--
-- To enable logging with CloudWatch Logs, the name should only contain
-- 0-9, A-Z, a-z, - and _.
newCreateActivity ::
  -- | 'name'
  Prelude.Text ->
  CreateActivity
newCreateActivity :: Text -> CreateActivity
newCreateActivity Text
pName_ =
  CreateActivity'
    { $sel:tags:CreateActivity' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateActivity' :: Text
name = Text
pName_
    }

-- | The list of tags to add to a resource.
--
-- An array of key-value pairs. For more information, see
-- <https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html Using Cost Allocation Tags>
-- in the /Amazon Web Services Billing and Cost Management User Guide/, and
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_iam-tags.html Controlling Access Using IAM Tags>.
--
-- Tags may only contain Unicode letters, digits, white space, or these
-- symbols: @_ . : \/ = + - \@@.
createActivity_tags :: Lens.Lens' CreateActivity (Prelude.Maybe [Tag])
createActivity_tags :: Lens' CreateActivity (Maybe [Tag])
createActivity_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateActivity' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateActivity' :: CreateActivity -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateActivity
s@CreateActivity' {} Maybe [Tag]
a -> CreateActivity
s {$sel:tags:CreateActivity' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateActivity) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the activity to create. This name must be unique for your
-- Amazon Web Services account and region for 90 days. For more
-- information, see
-- <https://docs.aws.amazon.com/step-functions/latest/dg/limits.html#service-limits-state-machine-executions Limits Related to State Machine Executions>
-- in the /Step Functions Developer Guide/.
--
-- A name must /not/ contain:
--
-- -   white space
--
-- -   brackets @\< > { } [ ]@
--
-- -   wildcard characters @? *@
--
-- -   special characters @\" # % \\ ^ | ~ \` $ & , ; : \/@
--
-- -   control characters (@U+0000-001F@, @U+007F-009F@)
--
-- To enable logging with CloudWatch Logs, the name should only contain
-- 0-9, A-Z, a-z, - and _.
createActivity_name :: Lens.Lens' CreateActivity Prelude.Text
createActivity_name :: Lens' CreateActivity Text
createActivity_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateActivity' {Text
name :: Text
$sel:name:CreateActivity' :: CreateActivity -> Text
name} -> Text
name) (\s :: CreateActivity
s@CreateActivity' {} Text
a -> CreateActivity
s {$sel:name:CreateActivity' :: Text
name = Text
a} :: CreateActivity)

instance Core.AWSRequest CreateActivity where
  type
    AWSResponse CreateActivity =
      CreateActivityResponse
  request :: (Service -> Service) -> CreateActivity -> Request CreateActivity
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateActivity
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateActivity)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> POSIX -> CreateActivityResponse
CreateActivityResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"activityArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"creationDate")
      )

instance Prelude.Hashable CreateActivity where
  hashWithSalt :: Int -> CreateActivity -> Int
hashWithSalt Int
_salt CreateActivity' {Maybe [Tag]
Text
name :: Text
tags :: Maybe [Tag]
$sel:name:CreateActivity' :: CreateActivity -> Text
$sel:tags:CreateActivity' :: CreateActivity -> Maybe [Tag]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData CreateActivity where
  rnf :: CreateActivity -> ()
rnf CreateActivity' {Maybe [Tag]
Text
name :: Text
tags :: Maybe [Tag]
$sel:name:CreateActivity' :: CreateActivity -> Text
$sel:tags:CreateActivity' :: CreateActivity -> Maybe [Tag]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders CreateActivity where
  toHeaders :: CreateActivity -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"AWSStepFunctions.CreateActivity" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateActivity where
  toJSON :: CreateActivity -> Value
toJSON CreateActivity' {Maybe [Tag]
Text
name :: Text
tags :: Maybe [Tag]
$sel:name:CreateActivity' :: CreateActivity -> Text
$sel:tags:CreateActivity' :: CreateActivity -> Maybe [Tag]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"tags" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

instance Data.ToPath CreateActivity where
  toPath :: CreateActivity -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery CreateActivity where
  toQuery :: CreateActivity -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateActivityResponse' smart constructor.
data CreateActivityResponse = CreateActivityResponse'
  { -- | The response's http status code.
    CreateActivityResponse -> Int
httpStatus :: Prelude.Int,
    -- | The Amazon Resource Name (ARN) that identifies the created activity.
    CreateActivityResponse -> Text
activityArn :: Prelude.Text,
    -- | The date the activity is created.
    CreateActivityResponse -> POSIX
creationDate :: Data.POSIX
  }
  deriving (CreateActivityResponse -> CreateActivityResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateActivityResponse -> CreateActivityResponse -> Bool
$c/= :: CreateActivityResponse -> CreateActivityResponse -> Bool
== :: CreateActivityResponse -> CreateActivityResponse -> Bool
$c== :: CreateActivityResponse -> CreateActivityResponse -> Bool
Prelude.Eq, ReadPrec [CreateActivityResponse]
ReadPrec CreateActivityResponse
Int -> ReadS CreateActivityResponse
ReadS [CreateActivityResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateActivityResponse]
$creadListPrec :: ReadPrec [CreateActivityResponse]
readPrec :: ReadPrec CreateActivityResponse
$creadPrec :: ReadPrec CreateActivityResponse
readList :: ReadS [CreateActivityResponse]
$creadList :: ReadS [CreateActivityResponse]
readsPrec :: Int -> ReadS CreateActivityResponse
$creadsPrec :: Int -> ReadS CreateActivityResponse
Prelude.Read, Int -> CreateActivityResponse -> ShowS
[CreateActivityResponse] -> ShowS
CreateActivityResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateActivityResponse] -> ShowS
$cshowList :: [CreateActivityResponse] -> ShowS
show :: CreateActivityResponse -> String
$cshow :: CreateActivityResponse -> String
showsPrec :: Int -> CreateActivityResponse -> ShowS
$cshowsPrec :: Int -> CreateActivityResponse -> ShowS
Prelude.Show, forall x. Rep CreateActivityResponse x -> CreateActivityResponse
forall x. CreateActivityResponse -> Rep CreateActivityResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateActivityResponse x -> CreateActivityResponse
$cfrom :: forall x. CreateActivityResponse -> Rep CreateActivityResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateActivityResponse' 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:
--
-- 'httpStatus', 'createActivityResponse_httpStatus' - The response's http status code.
--
-- 'activityArn', 'createActivityResponse_activityArn' - The Amazon Resource Name (ARN) that identifies the created activity.
--
-- 'creationDate', 'createActivityResponse_creationDate' - The date the activity is created.
newCreateActivityResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'activityArn'
  Prelude.Text ->
  -- | 'creationDate'
  Prelude.UTCTime ->
  CreateActivityResponse
newCreateActivityResponse :: Int -> Text -> UTCTime -> CreateActivityResponse
newCreateActivityResponse
  Int
pHttpStatus_
  Text
pActivityArn_
  UTCTime
pCreationDate_ =
    CreateActivityResponse'
      { $sel:httpStatus:CreateActivityResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:activityArn:CreateActivityResponse' :: Text
activityArn = Text
pActivityArn_,
        $sel:creationDate:CreateActivityResponse' :: POSIX
creationDate = forall (a :: Format). Iso' (Time a) UTCTime
Data._Time forall t b. AReview t b -> b -> t
Lens.# UTCTime
pCreationDate_
      }

-- | The response's http status code.
createActivityResponse_httpStatus :: Lens.Lens' CreateActivityResponse Prelude.Int
createActivityResponse_httpStatus :: Lens' CreateActivityResponse Int
createActivityResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateActivityResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateActivityResponse' :: CreateActivityResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateActivityResponse
s@CreateActivityResponse' {} Int
a -> CreateActivityResponse
s {$sel:httpStatus:CreateActivityResponse' :: Int
httpStatus = Int
a} :: CreateActivityResponse)

-- | The Amazon Resource Name (ARN) that identifies the created activity.
createActivityResponse_activityArn :: Lens.Lens' CreateActivityResponse Prelude.Text
createActivityResponse_activityArn :: Lens' CreateActivityResponse Text
createActivityResponse_activityArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateActivityResponse' {Text
activityArn :: Text
$sel:activityArn:CreateActivityResponse' :: CreateActivityResponse -> Text
activityArn} -> Text
activityArn) (\s :: CreateActivityResponse
s@CreateActivityResponse' {} Text
a -> CreateActivityResponse
s {$sel:activityArn:CreateActivityResponse' :: Text
activityArn = Text
a} :: CreateActivityResponse)

-- | The date the activity is created.
createActivityResponse_creationDate :: Lens.Lens' CreateActivityResponse Prelude.UTCTime
createActivityResponse_creationDate :: Lens' CreateActivityResponse UTCTime
createActivityResponse_creationDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateActivityResponse' {POSIX
creationDate :: POSIX
$sel:creationDate:CreateActivityResponse' :: CreateActivityResponse -> POSIX
creationDate} -> POSIX
creationDate) (\s :: CreateActivityResponse
s@CreateActivityResponse' {} POSIX
a -> CreateActivityResponse
s {$sel:creationDate:CreateActivityResponse' :: POSIX
creationDate = POSIX
a} :: CreateActivityResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Prelude.NFData CreateActivityResponse where
  rnf :: CreateActivityResponse -> ()
rnf CreateActivityResponse' {Int
Text
POSIX
creationDate :: POSIX
activityArn :: Text
httpStatus :: Int
$sel:creationDate:CreateActivityResponse' :: CreateActivityResponse -> POSIX
$sel:activityArn:CreateActivityResponse' :: CreateActivityResponse -> Text
$sel:httpStatus:CreateActivityResponse' :: CreateActivityResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
activityArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf POSIX
creationDate