{-# 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.GameLift.ListFleets
-- 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)
--
-- Retrieves a collection of fleet records for this AWS account. You can
-- filter the result set by build ID. Use the pagination parameters to
-- retrieve results in sequential pages.
--
-- Fleet records are not listed in any particular order.
module Network.AWS.GameLift.ListFleets
    (
    -- * Creating a Request
      listFleets
    , ListFleets
    -- * Request Lenses
    , lfBuildId
    , lfNextToken
    , lfLimit

    -- * Destructuring the Response
    , listFleetsResponse
    , ListFleetsResponse
    -- * Response Lenses
    , lfrsNextToken
    , lfrsFleetIds
    , lfrsResponseStatus
    ) where

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

-- | Represents the input for a request action.
--
-- /See:/ 'listFleets' smart constructor.
data ListFleets = ListFleets'
    { _lfBuildId   :: !(Maybe Text)
    , _lfNextToken :: !(Maybe Text)
    , _lfLimit     :: !(Maybe Nat)
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'ListFleets' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'lfBuildId'
--
-- * 'lfNextToken'
--
-- * 'lfLimit'
listFleets
    :: ListFleets
listFleets =
    ListFleets'
    { _lfBuildId = Nothing
    , _lfNextToken = Nothing
    , _lfLimit = Nothing
    }

-- | Unique identifier of the build to return fleets for. Use this parameter
-- to return only fleets using the specified build. To retrieve all fleets,
-- leave this parameter empty.
lfBuildId :: Lens' ListFleets (Maybe Text)
lfBuildId = lens _lfBuildId (\ s a -> s{_lfBuildId = a});

-- | Token indicating the start of the next sequential page of results. Use
-- the token that is returned with a previous call to this action. To
-- specify the start of the result set, do not specify a value.
lfNextToken :: Lens' ListFleets (Maybe Text)
lfNextToken = lens _lfNextToken (\ s a -> s{_lfNextToken = a});

-- | Maximum number of results to return. You can use this parameter with
-- /NextToken/ to get results as a set of sequential pages.
lfLimit :: Lens' ListFleets (Maybe Natural)
lfLimit = lens _lfLimit (\ s a -> s{_lfLimit = a}) . mapping _Nat;

instance AWSRequest ListFleets where
        type Rs ListFleets = ListFleetsResponse
        request = postJSON gameLift
        response
          = receiveJSON
              (\ s h x ->
                 ListFleetsResponse' <$>
                   (x .?> "NextToken") <*> (x .?> "FleetIds") <*>
                     (pure (fromEnum s)))

instance Hashable ListFleets

instance NFData ListFleets

instance ToHeaders ListFleets where
        toHeaders
          = const
              (mconcat
                 ["X-Amz-Target" =#
                    ("GameLift.ListFleets" :: ByteString),
                  "Content-Type" =#
                    ("application/x-amz-json-1.1" :: ByteString)])

instance ToJSON ListFleets where
        toJSON ListFleets'{..}
          = object
              (catMaybes
                 [("BuildId" .=) <$> _lfBuildId,
                  ("NextToken" .=) <$> _lfNextToken,
                  ("Limit" .=) <$> _lfLimit])

instance ToPath ListFleets where
        toPath = const "/"

instance ToQuery ListFleets where
        toQuery = const mempty

-- | Represents the returned data in response to a request action.
--
-- /See:/ 'listFleetsResponse' smart constructor.
data ListFleetsResponse = ListFleetsResponse'
    { _lfrsNextToken      :: !(Maybe Text)
    , _lfrsFleetIds       :: !(Maybe (List1 Text))
    , _lfrsResponseStatus :: !Int
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'ListFleetsResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'lfrsNextToken'
--
-- * 'lfrsFleetIds'
--
-- * 'lfrsResponseStatus'
listFleetsResponse
    :: Int -- ^ 'lfrsResponseStatus'
    -> ListFleetsResponse
listFleetsResponse pResponseStatus_ =
    ListFleetsResponse'
    { _lfrsNextToken = Nothing
    , _lfrsFleetIds = Nothing
    , _lfrsResponseStatus = pResponseStatus_
    }

-- | Token indicating where to resume retrieving results on the next call to
-- this action. If no token is returned, these results represent the end of
-- the list.
--
-- If a request has a limit that exactly matches the number of remaining
-- results, a token is returned even though there are no more results to
-- retrieve.
lfrsNextToken :: Lens' ListFleetsResponse (Maybe Text)
lfrsNextToken = lens _lfrsNextToken (\ s a -> s{_lfrsNextToken = a});

-- | Set of fleet IDs matching the list request. You can retrieve additional
-- information about all returned fleets by passing this result set to a
-- call to < DescribeFleetAttributes>, < DescribeFleetCapacity>, and
-- < DescribeFleetUtilization>.
lfrsFleetIds :: Lens' ListFleetsResponse (Maybe (NonEmpty Text))
lfrsFleetIds = lens _lfrsFleetIds (\ s a -> s{_lfrsFleetIds = a}) . mapping _List1;

-- | The response status code.
lfrsResponseStatus :: Lens' ListFleetsResponse Int
lfrsResponseStatus = lens _lfrsResponseStatus (\ s a -> s{_lfrsResponseStatus = a});

instance NFData ListFleetsResponse