{-# 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.APIGateway.GetUsage
-- Copyright   : (c) 2013-2016 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)
--
-- Gets the usage data of a usage plan in a specified time interval.
--
--
module Network.AWS.APIGateway.GetUsage
    (
    -- * Creating a Request
      getUsage
    , GetUsage
    -- * Request Lenses
    , guKeyId
    , guLimit
    , guPosition
    , guUsagePlanId
    , guStartDate
    , guEndDate

    -- * Destructuring the Response
    , usage
    , Usage
    -- * Response Lenses
    , uUsagePlanId
    , uEndDate
    , uItems
    , uStartDate
    , uPosition
    ) where

import           Network.AWS.APIGateway.Types
import           Network.AWS.APIGateway.Types.Product
import           Network.AWS.Lens
import           Network.AWS.Prelude
import           Network.AWS.Request
import           Network.AWS.Response

-- | The GET request to get the usage data of a usage plan in a specified time interval.
--
--
--
-- /See:/ 'getUsage' smart constructor.
data GetUsage = GetUsage'
    { _guKeyId       :: !(Maybe Text)
    , _guLimit       :: !(Maybe Int)
    , _guPosition    :: !(Maybe Text)
    , _guUsagePlanId :: !Text
    , _guStartDate   :: !Text
    , _guEndDate     :: !Text
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'GetUsage' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'guKeyId' - The Id of the API key associated with the resultant usage data.
--
-- * 'guLimit' - The maximum number of results to be returned.
--
-- * 'guPosition' - Position
--
-- * 'guUsagePlanId' - The Id of the usage plan associated with the usage data.
--
-- * 'guStartDate' - The starting date (e.g., 2016-01-01) of the usage data.
--
-- * 'guEndDate' - The ending date (e.g., 2016-12-31) of the usage data.
getUsage
    :: Text -- ^ 'guUsagePlanId'
    -> Text -- ^ 'guStartDate'
    -> Text -- ^ 'guEndDate'
    -> GetUsage
getUsage pUsagePlanId_ pStartDate_ pEndDate_ =
    GetUsage'
    { _guKeyId = Nothing
    , _guLimit = Nothing
    , _guPosition = Nothing
    , _guUsagePlanId = pUsagePlanId_
    , _guStartDate = pStartDate_
    , _guEndDate = pEndDate_
    }

-- | The Id of the API key associated with the resultant usage data.
guKeyId :: Lens' GetUsage (Maybe Text)
guKeyId = lens _guKeyId (\ s a -> s{_guKeyId = a});

-- | The maximum number of results to be returned.
guLimit :: Lens' GetUsage (Maybe Int)
guLimit = lens _guLimit (\ s a -> s{_guLimit = a});

-- | Position
guPosition :: Lens' GetUsage (Maybe Text)
guPosition = lens _guPosition (\ s a -> s{_guPosition = a});

-- | The Id of the usage plan associated with the usage data.
guUsagePlanId :: Lens' GetUsage Text
guUsagePlanId = lens _guUsagePlanId (\ s a -> s{_guUsagePlanId = a});

-- | The starting date (e.g., 2016-01-01) of the usage data.
guStartDate :: Lens' GetUsage Text
guStartDate = lens _guStartDate (\ s a -> s{_guStartDate = a});

-- | The ending date (e.g., 2016-12-31) of the usage data.
guEndDate :: Lens' GetUsage Text
guEndDate = lens _guEndDate (\ s a -> s{_guEndDate = a});

instance AWSRequest GetUsage where
        type Rs GetUsage = Usage
        request = get apiGateway
        response = receiveJSON (\ s h x -> eitherParseJSON x)

instance Hashable GetUsage

instance NFData GetUsage

instance ToHeaders GetUsage where
        toHeaders
          = const
              (mconcat
                 ["Accept" =# ("application/json" :: ByteString)])

instance ToPath GetUsage where
        toPath GetUsage'{..}
          = mconcat
              ["/usageplans/", toBS _guUsagePlanId, "/usage"]

instance ToQuery GetUsage where
        toQuery GetUsage'{..}
          = mconcat
              ["keyId" =: _guKeyId, "limit" =: _guLimit,
               "position" =: _guPosition,
               "startDate" =: _guStartDate, "endDate" =: _guEndDate]