{-# 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.AutoScalingPlans.CreateScalingPlan
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a scaling plan.
module Amazonka.AutoScalingPlans.CreateScalingPlan
  ( -- * Creating a Request
    CreateScalingPlan (..),
    newCreateScalingPlan,

    -- * Request Lenses
    createScalingPlan_scalingPlanName,
    createScalingPlan_applicationSource,
    createScalingPlan_scalingInstructions,

    -- * Destructuring the Response
    CreateScalingPlanResponse (..),
    newCreateScalingPlanResponse,

    -- * Response Lenses
    createScalingPlanResponse_httpStatus,
    createScalingPlanResponse_scalingPlanVersion,
  )
where

import Amazonka.AutoScalingPlans.Types
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

-- | /See:/ 'newCreateScalingPlan' smart constructor.
data CreateScalingPlan = CreateScalingPlan'
  { -- | The name of the scaling plan. Names cannot contain vertical bars,
    -- colons, or forward slashes.
    CreateScalingPlan -> Text
scalingPlanName :: Prelude.Text,
    -- | A CloudFormation stack or set of tags. You can create one scaling plan
    -- per application source.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ApplicationSource.html ApplicationSource>
    -- in the /AWS Auto Scaling API Reference/.
    CreateScalingPlan -> ApplicationSource
applicationSource :: ApplicationSource,
    -- | The scaling instructions.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ScalingInstruction.html ScalingInstruction>
    -- in the /AWS Auto Scaling API Reference/.
    CreateScalingPlan -> [ScalingInstruction]
scalingInstructions :: [ScalingInstruction]
  }
  deriving (CreateScalingPlan -> CreateScalingPlan -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateScalingPlan -> CreateScalingPlan -> Bool
$c/= :: CreateScalingPlan -> CreateScalingPlan -> Bool
== :: CreateScalingPlan -> CreateScalingPlan -> Bool
$c== :: CreateScalingPlan -> CreateScalingPlan -> Bool
Prelude.Eq, ReadPrec [CreateScalingPlan]
ReadPrec CreateScalingPlan
Int -> ReadS CreateScalingPlan
ReadS [CreateScalingPlan]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateScalingPlan]
$creadListPrec :: ReadPrec [CreateScalingPlan]
readPrec :: ReadPrec CreateScalingPlan
$creadPrec :: ReadPrec CreateScalingPlan
readList :: ReadS [CreateScalingPlan]
$creadList :: ReadS [CreateScalingPlan]
readsPrec :: Int -> ReadS CreateScalingPlan
$creadsPrec :: Int -> ReadS CreateScalingPlan
Prelude.Read, Int -> CreateScalingPlan -> ShowS
[CreateScalingPlan] -> ShowS
CreateScalingPlan -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateScalingPlan] -> ShowS
$cshowList :: [CreateScalingPlan] -> ShowS
show :: CreateScalingPlan -> String
$cshow :: CreateScalingPlan -> String
showsPrec :: Int -> CreateScalingPlan -> ShowS
$cshowsPrec :: Int -> CreateScalingPlan -> ShowS
Prelude.Show, forall x. Rep CreateScalingPlan x -> CreateScalingPlan
forall x. CreateScalingPlan -> Rep CreateScalingPlan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateScalingPlan x -> CreateScalingPlan
$cfrom :: forall x. CreateScalingPlan -> Rep CreateScalingPlan x
Prelude.Generic)

-- |
-- Create a value of 'CreateScalingPlan' 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:
--
-- 'scalingPlanName', 'createScalingPlan_scalingPlanName' - The name of the scaling plan. Names cannot contain vertical bars,
-- colons, or forward slashes.
--
-- 'applicationSource', 'createScalingPlan_applicationSource' - A CloudFormation stack or set of tags. You can create one scaling plan
-- per application source.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ApplicationSource.html ApplicationSource>
-- in the /AWS Auto Scaling API Reference/.
--
-- 'scalingInstructions', 'createScalingPlan_scalingInstructions' - The scaling instructions.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ScalingInstruction.html ScalingInstruction>
-- in the /AWS Auto Scaling API Reference/.
newCreateScalingPlan ::
  -- | 'scalingPlanName'
  Prelude.Text ->
  -- | 'applicationSource'
  ApplicationSource ->
  CreateScalingPlan
newCreateScalingPlan :: Text -> ApplicationSource -> CreateScalingPlan
newCreateScalingPlan
  Text
pScalingPlanName_
  ApplicationSource
pApplicationSource_ =
    CreateScalingPlan'
      { $sel:scalingPlanName:CreateScalingPlan' :: Text
scalingPlanName =
          Text
pScalingPlanName_,
        $sel:applicationSource:CreateScalingPlan' :: ApplicationSource
applicationSource = ApplicationSource
pApplicationSource_,
        $sel:scalingInstructions:CreateScalingPlan' :: [ScalingInstruction]
scalingInstructions = forall a. Monoid a => a
Prelude.mempty
      }

-- | The name of the scaling plan. Names cannot contain vertical bars,
-- colons, or forward slashes.
createScalingPlan_scalingPlanName :: Lens.Lens' CreateScalingPlan Prelude.Text
createScalingPlan_scalingPlanName :: Lens' CreateScalingPlan Text
createScalingPlan_scalingPlanName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScalingPlan' {Text
scalingPlanName :: Text
$sel:scalingPlanName:CreateScalingPlan' :: CreateScalingPlan -> Text
scalingPlanName} -> Text
scalingPlanName) (\s :: CreateScalingPlan
s@CreateScalingPlan' {} Text
a -> CreateScalingPlan
s {$sel:scalingPlanName:CreateScalingPlan' :: Text
scalingPlanName = Text
a} :: CreateScalingPlan)

-- | A CloudFormation stack or set of tags. You can create one scaling plan
-- per application source.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ApplicationSource.html ApplicationSource>
-- in the /AWS Auto Scaling API Reference/.
createScalingPlan_applicationSource :: Lens.Lens' CreateScalingPlan ApplicationSource
createScalingPlan_applicationSource :: Lens' CreateScalingPlan ApplicationSource
createScalingPlan_applicationSource = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScalingPlan' {ApplicationSource
applicationSource :: ApplicationSource
$sel:applicationSource:CreateScalingPlan' :: CreateScalingPlan -> ApplicationSource
applicationSource} -> ApplicationSource
applicationSource) (\s :: CreateScalingPlan
s@CreateScalingPlan' {} ApplicationSource
a -> CreateScalingPlan
s {$sel:applicationSource:CreateScalingPlan' :: ApplicationSource
applicationSource = ApplicationSource
a} :: CreateScalingPlan)

-- | The scaling instructions.
--
-- For more information, see
-- <https://docs.aws.amazon.com/autoscaling/plans/APIReference/API_ScalingInstruction.html ScalingInstruction>
-- in the /AWS Auto Scaling API Reference/.
createScalingPlan_scalingInstructions :: Lens.Lens' CreateScalingPlan [ScalingInstruction]
createScalingPlan_scalingInstructions :: Lens' CreateScalingPlan [ScalingInstruction]
createScalingPlan_scalingInstructions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScalingPlan' {[ScalingInstruction]
scalingInstructions :: [ScalingInstruction]
$sel:scalingInstructions:CreateScalingPlan' :: CreateScalingPlan -> [ScalingInstruction]
scalingInstructions} -> [ScalingInstruction]
scalingInstructions) (\s :: CreateScalingPlan
s@CreateScalingPlan' {} [ScalingInstruction]
a -> CreateScalingPlan
s {$sel:scalingInstructions:CreateScalingPlan' :: [ScalingInstruction]
scalingInstructions = [ScalingInstruction]
a} :: CreateScalingPlan) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest CreateScalingPlan where
  type
    AWSResponse CreateScalingPlan =
      CreateScalingPlanResponse
  request :: (Service -> Service)
-> CreateScalingPlan -> Request CreateScalingPlan
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 CreateScalingPlan
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateScalingPlan)))
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 ->
          Int -> Integer -> CreateScalingPlanResponse
CreateScalingPlanResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"ScalingPlanVersion")
      )

instance Prelude.Hashable CreateScalingPlan where
  hashWithSalt :: Int -> CreateScalingPlan -> Int
hashWithSalt Int
_salt CreateScalingPlan' {[ScalingInstruction]
Text
ApplicationSource
scalingInstructions :: [ScalingInstruction]
applicationSource :: ApplicationSource
scalingPlanName :: Text
$sel:scalingInstructions:CreateScalingPlan' :: CreateScalingPlan -> [ScalingInstruction]
$sel:applicationSource:CreateScalingPlan' :: CreateScalingPlan -> ApplicationSource
$sel:scalingPlanName:CreateScalingPlan' :: CreateScalingPlan -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
scalingPlanName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ApplicationSource
applicationSource
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ScalingInstruction]
scalingInstructions

instance Prelude.NFData CreateScalingPlan where
  rnf :: CreateScalingPlan -> ()
rnf CreateScalingPlan' {[ScalingInstruction]
Text
ApplicationSource
scalingInstructions :: [ScalingInstruction]
applicationSource :: ApplicationSource
scalingPlanName :: Text
$sel:scalingInstructions:CreateScalingPlan' :: CreateScalingPlan -> [ScalingInstruction]
$sel:applicationSource:CreateScalingPlan' :: CreateScalingPlan -> ApplicationSource
$sel:scalingPlanName:CreateScalingPlan' :: CreateScalingPlan -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
scalingPlanName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ApplicationSource
applicationSource
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ScalingInstruction]
scalingInstructions

instance Data.ToHeaders CreateScalingPlan where
  toHeaders :: CreateScalingPlan -> 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
"AnyScaleScalingPlannerFrontendService.CreateScalingPlan" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateScalingPlan where
  toJSON :: CreateScalingPlan -> Value
toJSON CreateScalingPlan' {[ScalingInstruction]
Text
ApplicationSource
scalingInstructions :: [ScalingInstruction]
applicationSource :: ApplicationSource
scalingPlanName :: Text
$sel:scalingInstructions:CreateScalingPlan' :: CreateScalingPlan -> [ScalingInstruction]
$sel:applicationSource:CreateScalingPlan' :: CreateScalingPlan -> ApplicationSource
$sel:scalingPlanName:CreateScalingPlan' :: CreateScalingPlan -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ScalingPlanName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
scalingPlanName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ApplicationSource" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ApplicationSource
applicationSource),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ScalingInstructions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [ScalingInstruction]
scalingInstructions)
          ]
      )

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

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

-- | /See:/ 'newCreateScalingPlanResponse' smart constructor.
data CreateScalingPlanResponse = CreateScalingPlanResponse'
  { -- | The response's http status code.
    CreateScalingPlanResponse -> Int
httpStatus :: Prelude.Int,
    -- | The version number of the scaling plan. This value is always @1@.
    -- Currently, you cannot have multiple scaling plan versions.
    CreateScalingPlanResponse -> Integer
scalingPlanVersion :: Prelude.Integer
  }
  deriving (CreateScalingPlanResponse -> CreateScalingPlanResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateScalingPlanResponse -> CreateScalingPlanResponse -> Bool
$c/= :: CreateScalingPlanResponse -> CreateScalingPlanResponse -> Bool
== :: CreateScalingPlanResponse -> CreateScalingPlanResponse -> Bool
$c== :: CreateScalingPlanResponse -> CreateScalingPlanResponse -> Bool
Prelude.Eq, ReadPrec [CreateScalingPlanResponse]
ReadPrec CreateScalingPlanResponse
Int -> ReadS CreateScalingPlanResponse
ReadS [CreateScalingPlanResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateScalingPlanResponse]
$creadListPrec :: ReadPrec [CreateScalingPlanResponse]
readPrec :: ReadPrec CreateScalingPlanResponse
$creadPrec :: ReadPrec CreateScalingPlanResponse
readList :: ReadS [CreateScalingPlanResponse]
$creadList :: ReadS [CreateScalingPlanResponse]
readsPrec :: Int -> ReadS CreateScalingPlanResponse
$creadsPrec :: Int -> ReadS CreateScalingPlanResponse
Prelude.Read, Int -> CreateScalingPlanResponse -> ShowS
[CreateScalingPlanResponse] -> ShowS
CreateScalingPlanResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateScalingPlanResponse] -> ShowS
$cshowList :: [CreateScalingPlanResponse] -> ShowS
show :: CreateScalingPlanResponse -> String
$cshow :: CreateScalingPlanResponse -> String
showsPrec :: Int -> CreateScalingPlanResponse -> ShowS
$cshowsPrec :: Int -> CreateScalingPlanResponse -> ShowS
Prelude.Show, forall x.
Rep CreateScalingPlanResponse x -> CreateScalingPlanResponse
forall x.
CreateScalingPlanResponse -> Rep CreateScalingPlanResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateScalingPlanResponse x -> CreateScalingPlanResponse
$cfrom :: forall x.
CreateScalingPlanResponse -> Rep CreateScalingPlanResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateScalingPlanResponse' 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:
--
-- 'httpStatus', 'createScalingPlanResponse_httpStatus' - The response's http status code.
--
-- 'scalingPlanVersion', 'createScalingPlanResponse_scalingPlanVersion' - The version number of the scaling plan. This value is always @1@.
-- Currently, you cannot have multiple scaling plan versions.
newCreateScalingPlanResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'scalingPlanVersion'
  Prelude.Integer ->
  CreateScalingPlanResponse
newCreateScalingPlanResponse :: Int -> Integer -> CreateScalingPlanResponse
newCreateScalingPlanResponse
  Int
pHttpStatus_
  Integer
pScalingPlanVersion_ =
    CreateScalingPlanResponse'
      { $sel:httpStatus:CreateScalingPlanResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:scalingPlanVersion:CreateScalingPlanResponse' :: Integer
scalingPlanVersion = Integer
pScalingPlanVersion_
      }

-- | The response's http status code.
createScalingPlanResponse_httpStatus :: Lens.Lens' CreateScalingPlanResponse Prelude.Int
createScalingPlanResponse_httpStatus :: Lens' CreateScalingPlanResponse Int
createScalingPlanResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScalingPlanResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateScalingPlanResponse' :: CreateScalingPlanResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateScalingPlanResponse
s@CreateScalingPlanResponse' {} Int
a -> CreateScalingPlanResponse
s {$sel:httpStatus:CreateScalingPlanResponse' :: Int
httpStatus = Int
a} :: CreateScalingPlanResponse)

-- | The version number of the scaling plan. This value is always @1@.
-- Currently, you cannot have multiple scaling plan versions.
createScalingPlanResponse_scalingPlanVersion :: Lens.Lens' CreateScalingPlanResponse Prelude.Integer
createScalingPlanResponse_scalingPlanVersion :: Lens' CreateScalingPlanResponse Integer
createScalingPlanResponse_scalingPlanVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateScalingPlanResponse' {Integer
scalingPlanVersion :: Integer
$sel:scalingPlanVersion:CreateScalingPlanResponse' :: CreateScalingPlanResponse -> Integer
scalingPlanVersion} -> Integer
scalingPlanVersion) (\s :: CreateScalingPlanResponse
s@CreateScalingPlanResponse' {} Integer
a -> CreateScalingPlanResponse
s {$sel:scalingPlanVersion:CreateScalingPlanResponse' :: Integer
scalingPlanVersion = Integer
a} :: CreateScalingPlanResponse)

instance Prelude.NFData CreateScalingPlanResponse where
  rnf :: CreateScalingPlanResponse -> ()
rnf CreateScalingPlanResponse' {Int
Integer
scalingPlanVersion :: Integer
httpStatus :: Int
$sel:scalingPlanVersion:CreateScalingPlanResponse' :: CreateScalingPlanResponse -> Integer
$sel:httpStatus:CreateScalingPlanResponse' :: CreateScalingPlanResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Integer
scalingPlanVersion