{-# 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.UpdateFleetCapacity
-- 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)
--
-- Updates capacity settings for a fleet. Use this action to specify the
-- number of EC2 instances (hosts) you want this fleet to contain. Before
-- calling this action, you may want to call < DescribeEC2InstanceLimits>
-- to get the maximum capacity based on the fleet\'s EC2 instance type.
--
-- If you\'re using auto-scaling (see < PutScalingPolicy>), you may want to
-- specify a minimum and\/or maximum capacity. If you don\'t provide these
-- boundaries, auto-scaling can set capacity anywhere between zero and the
-- <http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html#limits_gamelift service limits>.
--
-- To update fleet capacity, specify the fleet ID and the desired number of
-- instances. If successful, Amazon GameLift starts or terminates instances
-- so that the fleet\'s active instance count matches the desired instance
-- count. You can view a fleet\'s current capacity information by calling
-- < DescribeFleetCapacity>. If the desired instance count is higher than
-- the instance type\'s limit, the \"Limit Exceeded\" exception will occur.
module Network.AWS.GameLift.UpdateFleetCapacity
    (
    -- * Creating a Request
      updateFleetCapacity
    , UpdateFleetCapacity
    -- * Request Lenses
    , ufcMaxSize
    , ufcMinSize
    , ufcDesiredInstances
    , ufcFleetId

    -- * Destructuring the Response
    , updateFleetCapacityResponse
    , UpdateFleetCapacityResponse
    -- * Response Lenses
    , ufcrsFleetId
    , ufcrsResponseStatus
    ) 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:/ 'updateFleetCapacity' smart constructor.
data UpdateFleetCapacity = UpdateFleetCapacity'
    { _ufcMaxSize          :: !(Maybe Nat)
    , _ufcMinSize          :: !(Maybe Nat)
    , _ufcDesiredInstances :: !(Maybe Nat)
    , _ufcFleetId          :: !Text
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'UpdateFleetCapacity' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'ufcMaxSize'
--
-- * 'ufcMinSize'
--
-- * 'ufcDesiredInstances'
--
-- * 'ufcFleetId'
updateFleetCapacity
    :: Text -- ^ 'ufcFleetId'
    -> UpdateFleetCapacity
updateFleetCapacity pFleetId_ =
    UpdateFleetCapacity'
    { _ufcMaxSize = Nothing
    , _ufcMinSize = Nothing
    , _ufcDesiredInstances = Nothing
    , _ufcFleetId = pFleetId_
    }

-- | Maximum value allowed for the fleet\'s instance count. Default if not
-- set is 1.
ufcMaxSize :: Lens' UpdateFleetCapacity (Maybe Natural)
ufcMaxSize = lens _ufcMaxSize (\ s a -> s{_ufcMaxSize = a}) . mapping _Nat;

-- | Minimum value allowed for the fleet\'s instance count. Default if not
-- set is 0.
ufcMinSize :: Lens' UpdateFleetCapacity (Maybe Natural)
ufcMinSize = lens _ufcMinSize (\ s a -> s{_ufcMinSize = a}) . mapping _Nat;

-- | Number of EC2 instances you want this fleet to host.
ufcDesiredInstances :: Lens' UpdateFleetCapacity (Maybe Natural)
ufcDesiredInstances = lens _ufcDesiredInstances (\ s a -> s{_ufcDesiredInstances = a}) . mapping _Nat;

-- | Unique identifier for the fleet you want to update capacity for.
ufcFleetId :: Lens' UpdateFleetCapacity Text
ufcFleetId = lens _ufcFleetId (\ s a -> s{_ufcFleetId = a});

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

instance Hashable UpdateFleetCapacity

instance NFData UpdateFleetCapacity

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

instance ToJSON UpdateFleetCapacity where
        toJSON UpdateFleetCapacity'{..}
          = object
              (catMaybes
                 [("MaxSize" .=) <$> _ufcMaxSize,
                  ("MinSize" .=) <$> _ufcMinSize,
                  ("DesiredInstances" .=) <$> _ufcDesiredInstances,
                  Just ("FleetId" .= _ufcFleetId)])

instance ToPath UpdateFleetCapacity where
        toPath = const "/"

instance ToQuery UpdateFleetCapacity where
        toQuery = const mempty

-- | Represents the returned data in response to a request action.
--
-- /See:/ 'updateFleetCapacityResponse' smart constructor.
data UpdateFleetCapacityResponse = UpdateFleetCapacityResponse'
    { _ufcrsFleetId        :: !(Maybe Text)
    , _ufcrsResponseStatus :: !Int
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'UpdateFleetCapacityResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'ufcrsFleetId'
--
-- * 'ufcrsResponseStatus'
updateFleetCapacityResponse
    :: Int -- ^ 'ufcrsResponseStatus'
    -> UpdateFleetCapacityResponse
updateFleetCapacityResponse pResponseStatus_ =
    UpdateFleetCapacityResponse'
    { _ufcrsFleetId = Nothing
    , _ufcrsResponseStatus = pResponseStatus_
    }

-- | Unique identifier for the updated fleet.
ufcrsFleetId :: Lens' UpdateFleetCapacityResponse (Maybe Text)
ufcrsFleetId = lens _ufcrsFleetId (\ s a -> s{_ufcrsFleetId = a});

-- | The response status code.
ufcrsResponseStatus :: Lens' UpdateFleetCapacityResponse Int
ufcrsResponseStatus = lens _ufcrsResponseStatus (\ s a -> s{_ufcrsResponseStatus = a});

instance NFData UpdateFleetCapacityResponse