{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE TypeFamilies       #-}

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds   #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

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

-- |
-- Module      : Network.AWS.IoT.ListTopicRules
-- Copyright   : (c) 2013-2015 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the rules for the specific topic.
--
-- /See:/ <https://aws.amazon.com/iot#ListTopicRules.html AWS API Reference> for ListTopicRules.
module Network.AWS.IoT.ListTopicRules
    (
    -- * Creating a Request
      listTopicRules
    , ListTopicRules
    -- * Request Lenses
    , ltrRuleDisabled
    , ltrTopic
    , ltrNextToken
    , ltrMaxResults

    -- * Destructuring the Response
    , listTopicRulesResponse
    , ListTopicRulesResponse
    -- * Response Lenses
    , ltrrsRules
    , ltrrsNextToken
    , ltrrsResponseStatus
    ) where

import           Network.AWS.IoT.Types
import           Network.AWS.IoT.Types.Product
import           Network.AWS.Prelude
import           Network.AWS.Request
import           Network.AWS.Response

-- | The input for the ListTopicRules operation.
--
-- /See:/ 'listTopicRules' smart constructor.
data ListTopicRules = ListTopicRules'
    { _ltrRuleDisabled :: !(Maybe Bool)
    , _ltrTopic        :: !(Maybe Text)
    , _ltrNextToken    :: !(Maybe Text)
    , _ltrMaxResults   :: !(Maybe Nat)
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'ListTopicRules' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'ltrRuleDisabled'
--
-- * 'ltrTopic'
--
-- * 'ltrNextToken'
--
-- * 'ltrMaxResults'
listTopicRules
    :: ListTopicRules
listTopicRules =
    ListTopicRules'
    { _ltrRuleDisabled = Nothing
    , _ltrTopic = Nothing
    , _ltrNextToken = Nothing
    , _ltrMaxResults = Nothing
    }

-- | Specifies whether the rule is disabled.
ltrRuleDisabled :: Lens' ListTopicRules (Maybe Bool)
ltrRuleDisabled = lens _ltrRuleDisabled (\ s a -> s{_ltrRuleDisabled = a});

-- | The topic.
ltrTopic :: Lens' ListTopicRules (Maybe Text)
ltrTopic = lens _ltrTopic (\ s a -> s{_ltrTopic = a});

-- | A token used to retrieve the next value.
ltrNextToken :: Lens' ListTopicRules (Maybe Text)
ltrNextToken = lens _ltrNextToken (\ s a -> s{_ltrNextToken = a});

-- | The maximum number of results to return.
ltrMaxResults :: Lens' ListTopicRules (Maybe Natural)
ltrMaxResults = lens _ltrMaxResults (\ s a -> s{_ltrMaxResults = a}) . mapping _Nat;

instance AWSRequest ListTopicRules where
        type Rs ListTopicRules = ListTopicRulesResponse
        request = get ioT
        response
          = receiveJSON
              (\ s h x ->
                 ListTopicRulesResponse' <$>
                   (x .?> "rules" .!@ mempty) <*> (x .?> "nextToken")
                     <*> (pure (fromEnum s)))

instance ToHeaders ListTopicRules where
        toHeaders = const mempty

instance ToPath ListTopicRules where
        toPath = const "/rules"

instance ToQuery ListTopicRules where
        toQuery ListTopicRules'{..}
          = mconcat
              ["ruleDisabled" =: _ltrRuleDisabled,
               "topic" =: _ltrTopic, "nextToken" =: _ltrNextToken,
               "maxResults" =: _ltrMaxResults]

-- | The output from the ListTopicRules operation.
--
-- /See:/ 'listTopicRulesResponse' smart constructor.
data ListTopicRulesResponse = ListTopicRulesResponse'
    { _ltrrsRules          :: !(Maybe [TopicRuleListItem])
    , _ltrrsNextToken      :: !(Maybe Text)
    , _ltrrsResponseStatus :: !Int
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'ListTopicRulesResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'ltrrsRules'
--
-- * 'ltrrsNextToken'
--
-- * 'ltrrsResponseStatus'
listTopicRulesResponse
    :: Int -- ^ 'ltrrsResponseStatus'
    -> ListTopicRulesResponse
listTopicRulesResponse pResponseStatus_ =
    ListTopicRulesResponse'
    { _ltrrsRules = Nothing
    , _ltrrsNextToken = Nothing
    , _ltrrsResponseStatus = pResponseStatus_
    }

-- | The rules.
ltrrsRules :: Lens' ListTopicRulesResponse [TopicRuleListItem]
ltrrsRules = lens _ltrrsRules (\ s a -> s{_ltrrsRules = a}) . _Default . _Coerce;

-- | A token used to retrieve the next value.
ltrrsNextToken :: Lens' ListTopicRulesResponse (Maybe Text)
ltrrsNextToken = lens _ltrrsNextToken (\ s a -> s{_ltrrsNextToken = a});

-- | The response status code.
ltrrsResponseStatus :: Lens' ListTopicRulesResponse Int
ltrrsResponseStatus = lens _ltrrsResponseStatus (\ s a -> s{_ltrrsResponseStatus = a});