{-# 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.SWF.CountPendingDecisionTasks
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the estimated number of decision tasks in the specified task
-- list. The count returned is an approximation and isn\'t guaranteed to be
-- exact. If you specify a task list that no decision task was ever
-- scheduled in then @0@ is returned.
--
-- __Access Control__
--
-- You can use IAM policies to control this action\'s access to Amazon SWF
-- resources as follows:
--
-- -   Use a @Resource@ element with the domain name to limit the action to
--     only specified domains.
--
-- -   Use an @Action@ element to allow or deny permission to call this
--     action.
--
-- -   Constrain the @taskList.name@ parameter by using a @Condition@
--     element with the @swf:taskList.name@ key to allow the action to
--     access only certain task lists.
--
-- If the caller doesn\'t have sufficient permissions to invoke the action,
-- or the parameter values fall outside the specified constraints, the
-- action fails. The associated event attribute\'s @cause@ parameter is set
-- to @OPERATION_NOT_PERMITTED@. For details and example IAM policies, see
-- <https://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-dev-iam.html Using IAM to Manage Access to Amazon SWF Workflows>
-- in the /Amazon SWF Developer Guide/.
module Amazonka.SWF.CountPendingDecisionTasks
  ( -- * Creating a Request
    CountPendingDecisionTasks (..),
    newCountPendingDecisionTasks,

    -- * Request Lenses
    countPendingDecisionTasks_domain,
    countPendingDecisionTasks_taskList,

    -- * Destructuring the Response
    PendingTaskCount (..),
    newPendingTaskCount,

    -- * Response Lenses
    pendingTaskCount_truncated,
    pendingTaskCount_count,
  )
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.SWF.Types

-- | /See:/ 'newCountPendingDecisionTasks' smart constructor.
data CountPendingDecisionTasks = CountPendingDecisionTasks'
  { -- | The name of the domain that contains the task list.
    CountPendingDecisionTasks -> Text
domain :: Prelude.Text,
    -- | The name of the task list.
    CountPendingDecisionTasks -> TaskList
taskList :: TaskList
  }
  deriving (CountPendingDecisionTasks -> CountPendingDecisionTasks -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CountPendingDecisionTasks -> CountPendingDecisionTasks -> Bool
$c/= :: CountPendingDecisionTasks -> CountPendingDecisionTasks -> Bool
== :: CountPendingDecisionTasks -> CountPendingDecisionTasks -> Bool
$c== :: CountPendingDecisionTasks -> CountPendingDecisionTasks -> Bool
Prelude.Eq, ReadPrec [CountPendingDecisionTasks]
ReadPrec CountPendingDecisionTasks
Int -> ReadS CountPendingDecisionTasks
ReadS [CountPendingDecisionTasks]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CountPendingDecisionTasks]
$creadListPrec :: ReadPrec [CountPendingDecisionTasks]
readPrec :: ReadPrec CountPendingDecisionTasks
$creadPrec :: ReadPrec CountPendingDecisionTasks
readList :: ReadS [CountPendingDecisionTasks]
$creadList :: ReadS [CountPendingDecisionTasks]
readsPrec :: Int -> ReadS CountPendingDecisionTasks
$creadsPrec :: Int -> ReadS CountPendingDecisionTasks
Prelude.Read, Int -> CountPendingDecisionTasks -> ShowS
[CountPendingDecisionTasks] -> ShowS
CountPendingDecisionTasks -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CountPendingDecisionTasks] -> ShowS
$cshowList :: [CountPendingDecisionTasks] -> ShowS
show :: CountPendingDecisionTasks -> String
$cshow :: CountPendingDecisionTasks -> String
showsPrec :: Int -> CountPendingDecisionTasks -> ShowS
$cshowsPrec :: Int -> CountPendingDecisionTasks -> ShowS
Prelude.Show, forall x.
Rep CountPendingDecisionTasks x -> CountPendingDecisionTasks
forall x.
CountPendingDecisionTasks -> Rep CountPendingDecisionTasks x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CountPendingDecisionTasks x -> CountPendingDecisionTasks
$cfrom :: forall x.
CountPendingDecisionTasks -> Rep CountPendingDecisionTasks x
Prelude.Generic)

-- |
-- Create a value of 'CountPendingDecisionTasks' 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:
--
-- 'domain', 'countPendingDecisionTasks_domain' - The name of the domain that contains the task list.
--
-- 'taskList', 'countPendingDecisionTasks_taskList' - The name of the task list.
newCountPendingDecisionTasks ::
  -- | 'domain'
  Prelude.Text ->
  -- | 'taskList'
  TaskList ->
  CountPendingDecisionTasks
newCountPendingDecisionTasks :: Text -> TaskList -> CountPendingDecisionTasks
newCountPendingDecisionTasks Text
pDomain_ TaskList
pTaskList_ =
  CountPendingDecisionTasks'
    { $sel:domain:CountPendingDecisionTasks' :: Text
domain = Text
pDomain_,
      $sel:taskList:CountPendingDecisionTasks' :: TaskList
taskList = TaskList
pTaskList_
    }

-- | The name of the domain that contains the task list.
countPendingDecisionTasks_domain :: Lens.Lens' CountPendingDecisionTasks Prelude.Text
countPendingDecisionTasks_domain :: Lens' CountPendingDecisionTasks Text
countPendingDecisionTasks_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CountPendingDecisionTasks' {Text
domain :: Text
$sel:domain:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> Text
domain} -> Text
domain) (\s :: CountPendingDecisionTasks
s@CountPendingDecisionTasks' {} Text
a -> CountPendingDecisionTasks
s {$sel:domain:CountPendingDecisionTasks' :: Text
domain = Text
a} :: CountPendingDecisionTasks)

-- | The name of the task list.
countPendingDecisionTasks_taskList :: Lens.Lens' CountPendingDecisionTasks TaskList
countPendingDecisionTasks_taskList :: Lens' CountPendingDecisionTasks TaskList
countPendingDecisionTasks_taskList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CountPendingDecisionTasks' {TaskList
taskList :: TaskList
$sel:taskList:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> TaskList
taskList} -> TaskList
taskList) (\s :: CountPendingDecisionTasks
s@CountPendingDecisionTasks' {} TaskList
a -> CountPendingDecisionTasks
s {$sel:taskList:CountPendingDecisionTasks' :: TaskList
taskList = TaskList
a} :: CountPendingDecisionTasks)

instance Core.AWSRequest CountPendingDecisionTasks where
  type
    AWSResponse CountPendingDecisionTasks =
      PendingTaskCount
  request :: (Service -> Service)
-> CountPendingDecisionTasks -> Request CountPendingDecisionTasks
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 CountPendingDecisionTasks
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CountPendingDecisionTasks)))
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 -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable CountPendingDecisionTasks where
  hashWithSalt :: Int -> CountPendingDecisionTasks -> Int
hashWithSalt Int
_salt CountPendingDecisionTasks' {Text
TaskList
taskList :: TaskList
domain :: Text
$sel:taskList:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> TaskList
$sel:domain:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domain
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TaskList
taskList

instance Prelude.NFData CountPendingDecisionTasks where
  rnf :: CountPendingDecisionTasks -> ()
rnf CountPendingDecisionTasks' {Text
TaskList
taskList :: TaskList
domain :: Text
$sel:taskList:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> TaskList
$sel:domain:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
domain
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf TaskList
taskList

instance Data.ToHeaders CountPendingDecisionTasks where
  toHeaders :: CountPendingDecisionTasks -> 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
"SimpleWorkflowService.CountPendingDecisionTasks" ::
                          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 CountPendingDecisionTasks where
  toJSON :: CountPendingDecisionTasks -> Value
toJSON CountPendingDecisionTasks' {Text
TaskList
taskList :: TaskList
domain :: Text
$sel:taskList:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> TaskList
$sel:domain:CountPendingDecisionTasks' :: CountPendingDecisionTasks -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"domain" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
domain),
            forall a. a -> Maybe a
Prelude.Just (Key
"taskList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= TaskList
taskList)
          ]
      )

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

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