{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

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

-- |
-- Module      : Amazonka.AutoScaling.Types.DesiredConfiguration
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AutoScaling.Types.DesiredConfiguration where

import Amazonka.AutoScaling.Types.LaunchTemplateSpecification
import Amazonka.AutoScaling.Types.MixedInstancesPolicy
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the desired configuration for an instance refresh.
--
-- If you specify a desired configuration, you must specify either a
-- @LaunchTemplate@ or a @MixedInstancesPolicy@.
--
-- /See:/ 'newDesiredConfiguration' smart constructor.
data DesiredConfiguration = DesiredConfiguration'
  { DesiredConfiguration -> Maybe MixedInstancesPolicy
mixedInstancesPolicy :: Prelude.Maybe MixedInstancesPolicy,
    DesiredConfiguration -> Maybe LaunchTemplateSpecification
launchTemplate :: Prelude.Maybe LaunchTemplateSpecification
  }
  deriving (DesiredConfiguration -> DesiredConfiguration -> Bool
(DesiredConfiguration -> DesiredConfiguration -> Bool)
-> (DesiredConfiguration -> DesiredConfiguration -> Bool)
-> Eq DesiredConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DesiredConfiguration -> DesiredConfiguration -> Bool
$c/= :: DesiredConfiguration -> DesiredConfiguration -> Bool
== :: DesiredConfiguration -> DesiredConfiguration -> Bool
$c== :: DesiredConfiguration -> DesiredConfiguration -> Bool
Prelude.Eq, ReadPrec [DesiredConfiguration]
ReadPrec DesiredConfiguration
Int -> ReadS DesiredConfiguration
ReadS [DesiredConfiguration]
(Int -> ReadS DesiredConfiguration)
-> ReadS [DesiredConfiguration]
-> ReadPrec DesiredConfiguration
-> ReadPrec [DesiredConfiguration]
-> Read DesiredConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DesiredConfiguration]
$creadListPrec :: ReadPrec [DesiredConfiguration]
readPrec :: ReadPrec DesiredConfiguration
$creadPrec :: ReadPrec DesiredConfiguration
readList :: ReadS [DesiredConfiguration]
$creadList :: ReadS [DesiredConfiguration]
readsPrec :: Int -> ReadS DesiredConfiguration
$creadsPrec :: Int -> ReadS DesiredConfiguration
Prelude.Read, Int -> DesiredConfiguration -> ShowS
[DesiredConfiguration] -> ShowS
DesiredConfiguration -> String
(Int -> DesiredConfiguration -> ShowS)
-> (DesiredConfiguration -> String)
-> ([DesiredConfiguration] -> ShowS)
-> Show DesiredConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DesiredConfiguration] -> ShowS
$cshowList :: [DesiredConfiguration] -> ShowS
show :: DesiredConfiguration -> String
$cshow :: DesiredConfiguration -> String
showsPrec :: Int -> DesiredConfiguration -> ShowS
$cshowsPrec :: Int -> DesiredConfiguration -> ShowS
Prelude.Show, (forall x. DesiredConfiguration -> Rep DesiredConfiguration x)
-> (forall x. Rep DesiredConfiguration x -> DesiredConfiguration)
-> Generic DesiredConfiguration
forall x. Rep DesiredConfiguration x -> DesiredConfiguration
forall x. DesiredConfiguration -> Rep DesiredConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DesiredConfiguration x -> DesiredConfiguration
$cfrom :: forall x. DesiredConfiguration -> Rep DesiredConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'DesiredConfiguration' 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:
--
-- 'mixedInstancesPolicy', 'desiredConfiguration_mixedInstancesPolicy' - Undocumented member.
--
-- 'launchTemplate', 'desiredConfiguration_launchTemplate' - Undocumented member.
newDesiredConfiguration ::
  DesiredConfiguration
newDesiredConfiguration :: DesiredConfiguration
newDesiredConfiguration =
  DesiredConfiguration' :: Maybe MixedInstancesPolicy
-> Maybe LaunchTemplateSpecification -> DesiredConfiguration
DesiredConfiguration'
    { $sel:mixedInstancesPolicy:DesiredConfiguration' :: Maybe MixedInstancesPolicy
mixedInstancesPolicy =
        Maybe MixedInstancesPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:launchTemplate:DesiredConfiguration' :: Maybe LaunchTemplateSpecification
launchTemplate = Maybe LaunchTemplateSpecification
forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
desiredConfiguration_mixedInstancesPolicy :: Lens.Lens' DesiredConfiguration (Prelude.Maybe MixedInstancesPolicy)
desiredConfiguration_mixedInstancesPolicy :: (Maybe MixedInstancesPolicy -> f (Maybe MixedInstancesPolicy))
-> DesiredConfiguration -> f DesiredConfiguration
desiredConfiguration_mixedInstancesPolicy = (DesiredConfiguration -> Maybe MixedInstancesPolicy)
-> (DesiredConfiguration
    -> Maybe MixedInstancesPolicy -> DesiredConfiguration)
-> Lens
     DesiredConfiguration
     DesiredConfiguration
     (Maybe MixedInstancesPolicy)
     (Maybe MixedInstancesPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DesiredConfiguration' {Maybe MixedInstancesPolicy
mixedInstancesPolicy :: Maybe MixedInstancesPolicy
$sel:mixedInstancesPolicy:DesiredConfiguration' :: DesiredConfiguration -> Maybe MixedInstancesPolicy
mixedInstancesPolicy} -> Maybe MixedInstancesPolicy
mixedInstancesPolicy) (\s :: DesiredConfiguration
s@DesiredConfiguration' {} Maybe MixedInstancesPolicy
a -> DesiredConfiguration
s {$sel:mixedInstancesPolicy:DesiredConfiguration' :: Maybe MixedInstancesPolicy
mixedInstancesPolicy = Maybe MixedInstancesPolicy
a} :: DesiredConfiguration)

-- | Undocumented member.
desiredConfiguration_launchTemplate :: Lens.Lens' DesiredConfiguration (Prelude.Maybe LaunchTemplateSpecification)
desiredConfiguration_launchTemplate :: (Maybe LaunchTemplateSpecification
 -> f (Maybe LaunchTemplateSpecification))
-> DesiredConfiguration -> f DesiredConfiguration
desiredConfiguration_launchTemplate = (DesiredConfiguration -> Maybe LaunchTemplateSpecification)
-> (DesiredConfiguration
    -> Maybe LaunchTemplateSpecification -> DesiredConfiguration)
-> Lens
     DesiredConfiguration
     DesiredConfiguration
     (Maybe LaunchTemplateSpecification)
     (Maybe LaunchTemplateSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DesiredConfiguration' {Maybe LaunchTemplateSpecification
launchTemplate :: Maybe LaunchTemplateSpecification
$sel:launchTemplate:DesiredConfiguration' :: DesiredConfiguration -> Maybe LaunchTemplateSpecification
launchTemplate} -> Maybe LaunchTemplateSpecification
launchTemplate) (\s :: DesiredConfiguration
s@DesiredConfiguration' {} Maybe LaunchTemplateSpecification
a -> DesiredConfiguration
s {$sel:launchTemplate:DesiredConfiguration' :: Maybe LaunchTemplateSpecification
launchTemplate = Maybe LaunchTemplateSpecification
a} :: DesiredConfiguration)

instance Core.FromXML DesiredConfiguration where
  parseXML :: [Node] -> Either String DesiredConfiguration
parseXML [Node]
x =
    Maybe MixedInstancesPolicy
-> Maybe LaunchTemplateSpecification -> DesiredConfiguration
DesiredConfiguration'
      (Maybe MixedInstancesPolicy
 -> Maybe LaunchTemplateSpecification -> DesiredConfiguration)
-> Either String (Maybe MixedInstancesPolicy)
-> Either
     String (Maybe LaunchTemplateSpecification -> DesiredConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe MixedInstancesPolicy)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MixedInstancesPolicy")
      Either
  String (Maybe LaunchTemplateSpecification -> DesiredConfiguration)
-> Either String (Maybe LaunchTemplateSpecification)
-> Either String DesiredConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe LaunchTemplateSpecification)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"LaunchTemplate")

instance Prelude.Hashable DesiredConfiguration

instance Prelude.NFData DesiredConfiguration

instance Core.ToQuery DesiredConfiguration where
  toQuery :: DesiredConfiguration -> QueryString
toQuery DesiredConfiguration' {Maybe LaunchTemplateSpecification
Maybe MixedInstancesPolicy
launchTemplate :: Maybe LaunchTemplateSpecification
mixedInstancesPolicy :: Maybe MixedInstancesPolicy
$sel:launchTemplate:DesiredConfiguration' :: DesiredConfiguration -> Maybe LaunchTemplateSpecification
$sel:mixedInstancesPolicy:DesiredConfiguration' :: DesiredConfiguration -> Maybe MixedInstancesPolicy
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"MixedInstancesPolicy" ByteString -> Maybe MixedInstancesPolicy -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe MixedInstancesPolicy
mixedInstancesPolicy,
        ByteString
"LaunchTemplate" ByteString -> Maybe LaunchTemplateSpecification -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe LaunchTemplateSpecification
launchTemplate
      ]