{-# 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.KinesisAnalyticsV2.RollbackApplication
-- 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)
--
-- Reverts the application to the previous running version. You can roll
-- back an application if you suspect it is stuck in a transient status.
--
-- You can roll back an application only if it is in the @UPDATING@ or
-- @AUTOSCALING@ status.
--
-- When you rollback an application, it loads state data from the last
-- successful snapshot. If the application has no snapshots, Kinesis Data
-- Analytics rejects the rollback request.
--
-- This action is not supported for Kinesis Data Analytics for SQL
-- applications.
module Amazonka.KinesisAnalyticsV2.RollbackApplication
  ( -- * Creating a Request
    RollbackApplication (..),
    newRollbackApplication,

    -- * Request Lenses
    rollbackApplication_applicationName,
    rollbackApplication_currentApplicationVersionId,

    -- * Destructuring the Response
    RollbackApplicationResponse (..),
    newRollbackApplicationResponse,

    -- * Response Lenses
    rollbackApplicationResponse_httpStatus,
    rollbackApplicationResponse_applicationDetail,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.KinesisAnalyticsV2.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRollbackApplication' smart constructor.
data RollbackApplication = RollbackApplication'
  { -- | The name of the application.
    RollbackApplication -> Text
applicationName :: Prelude.Text,
    -- | The current application version ID. You can retrieve the application
    -- version ID using DescribeApplication.
    RollbackApplication -> Natural
currentApplicationVersionId :: Prelude.Natural
  }
  deriving (RollbackApplication -> RollbackApplication -> Bool
(RollbackApplication -> RollbackApplication -> Bool)
-> (RollbackApplication -> RollbackApplication -> Bool)
-> Eq RollbackApplication
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RollbackApplication -> RollbackApplication -> Bool
$c/= :: RollbackApplication -> RollbackApplication -> Bool
== :: RollbackApplication -> RollbackApplication -> Bool
$c== :: RollbackApplication -> RollbackApplication -> Bool
Prelude.Eq, ReadPrec [RollbackApplication]
ReadPrec RollbackApplication
Int -> ReadS RollbackApplication
ReadS [RollbackApplication]
(Int -> ReadS RollbackApplication)
-> ReadS [RollbackApplication]
-> ReadPrec RollbackApplication
-> ReadPrec [RollbackApplication]
-> Read RollbackApplication
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RollbackApplication]
$creadListPrec :: ReadPrec [RollbackApplication]
readPrec :: ReadPrec RollbackApplication
$creadPrec :: ReadPrec RollbackApplication
readList :: ReadS [RollbackApplication]
$creadList :: ReadS [RollbackApplication]
readsPrec :: Int -> ReadS RollbackApplication
$creadsPrec :: Int -> ReadS RollbackApplication
Prelude.Read, Int -> RollbackApplication -> ShowS
[RollbackApplication] -> ShowS
RollbackApplication -> String
(Int -> RollbackApplication -> ShowS)
-> (RollbackApplication -> String)
-> ([RollbackApplication] -> ShowS)
-> Show RollbackApplication
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RollbackApplication] -> ShowS
$cshowList :: [RollbackApplication] -> ShowS
show :: RollbackApplication -> String
$cshow :: RollbackApplication -> String
showsPrec :: Int -> RollbackApplication -> ShowS
$cshowsPrec :: Int -> RollbackApplication -> ShowS
Prelude.Show, (forall x. RollbackApplication -> Rep RollbackApplication x)
-> (forall x. Rep RollbackApplication x -> RollbackApplication)
-> Generic RollbackApplication
forall x. Rep RollbackApplication x -> RollbackApplication
forall x. RollbackApplication -> Rep RollbackApplication x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RollbackApplication x -> RollbackApplication
$cfrom :: forall x. RollbackApplication -> Rep RollbackApplication x
Prelude.Generic)

-- |
-- Create a value of 'RollbackApplication' 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:
--
-- 'applicationName', 'rollbackApplication_applicationName' - The name of the application.
--
-- 'currentApplicationVersionId', 'rollbackApplication_currentApplicationVersionId' - The current application version ID. You can retrieve the application
-- version ID using DescribeApplication.
newRollbackApplication ::
  -- | 'applicationName'
  Prelude.Text ->
  -- | 'currentApplicationVersionId'
  Prelude.Natural ->
  RollbackApplication
newRollbackApplication :: Text -> Natural -> RollbackApplication
newRollbackApplication
  Text
pApplicationName_
  Natural
pCurrentApplicationVersionId_ =
    RollbackApplication' :: Text -> Natural -> RollbackApplication
RollbackApplication'
      { $sel:applicationName:RollbackApplication' :: Text
applicationName =
          Text
pApplicationName_,
        $sel:currentApplicationVersionId:RollbackApplication' :: Natural
currentApplicationVersionId =
          Natural
pCurrentApplicationVersionId_
      }

-- | The name of the application.
rollbackApplication_applicationName :: Lens.Lens' RollbackApplication Prelude.Text
rollbackApplication_applicationName :: (Text -> f Text) -> RollbackApplication -> f RollbackApplication
rollbackApplication_applicationName = (RollbackApplication -> Text)
-> (RollbackApplication -> Text -> RollbackApplication)
-> Lens RollbackApplication RollbackApplication Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackApplication' {Text
applicationName :: Text
$sel:applicationName:RollbackApplication' :: RollbackApplication -> Text
applicationName} -> Text
applicationName) (\s :: RollbackApplication
s@RollbackApplication' {} Text
a -> RollbackApplication
s {$sel:applicationName:RollbackApplication' :: Text
applicationName = Text
a} :: RollbackApplication)

-- | The current application version ID. You can retrieve the application
-- version ID using DescribeApplication.
rollbackApplication_currentApplicationVersionId :: Lens.Lens' RollbackApplication Prelude.Natural
rollbackApplication_currentApplicationVersionId :: (Natural -> f Natural)
-> RollbackApplication -> f RollbackApplication
rollbackApplication_currentApplicationVersionId = (RollbackApplication -> Natural)
-> (RollbackApplication -> Natural -> RollbackApplication)
-> Lens RollbackApplication RollbackApplication Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackApplication' {Natural
currentApplicationVersionId :: Natural
$sel:currentApplicationVersionId:RollbackApplication' :: RollbackApplication -> Natural
currentApplicationVersionId} -> Natural
currentApplicationVersionId) (\s :: RollbackApplication
s@RollbackApplication' {} Natural
a -> RollbackApplication
s {$sel:currentApplicationVersionId:RollbackApplication' :: Natural
currentApplicationVersionId = Natural
a} :: RollbackApplication)

instance Core.AWSRequest RollbackApplication where
  type
    AWSResponse RollbackApplication =
      RollbackApplicationResponse
  request :: RollbackApplication -> Request RollbackApplication
request = Service -> RollbackApplication -> Request RollbackApplication
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RollbackApplication
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RollbackApplication)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RollbackApplication))
-> Logger
-> Service
-> Proxy RollbackApplication
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RollbackApplication)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> ApplicationDetail -> RollbackApplicationResponse
RollbackApplicationResponse'
            (Int -> ApplicationDetail -> RollbackApplicationResponse)
-> Either String Int
-> Either String (ApplicationDetail -> RollbackApplicationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (ApplicationDetail -> RollbackApplicationResponse)
-> Either String ApplicationDetail
-> Either String RollbackApplicationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String ApplicationDetail
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"ApplicationDetail")
      )

instance Prelude.Hashable RollbackApplication

instance Prelude.NFData RollbackApplication

instance Core.ToHeaders RollbackApplication where
  toHeaders :: RollbackApplication -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RollbackApplication -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"KinesisAnalytics_20180523.RollbackApplication" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON RollbackApplication where
  toJSON :: RollbackApplication -> Value
toJSON RollbackApplication' {Natural
Text
currentApplicationVersionId :: Natural
applicationName :: Text
$sel:currentApplicationVersionId:RollbackApplication' :: RollbackApplication -> Natural
$sel:applicationName:RollbackApplication' :: RollbackApplication -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ApplicationName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
applicationName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"CurrentApplicationVersionId"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
currentApplicationVersionId
              )
          ]
      )

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

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

-- | /See:/ 'newRollbackApplicationResponse' smart constructor.
data RollbackApplicationResponse = RollbackApplicationResponse'
  { -- | The response's http status code.
    RollbackApplicationResponse -> Int
httpStatus :: Prelude.Int,
    RollbackApplicationResponse -> ApplicationDetail
applicationDetail :: ApplicationDetail
  }
  deriving (RollbackApplicationResponse -> RollbackApplicationResponse -> Bool
(RollbackApplicationResponse
 -> RollbackApplicationResponse -> Bool)
-> (RollbackApplicationResponse
    -> RollbackApplicationResponse -> Bool)
-> Eq RollbackApplicationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RollbackApplicationResponse -> RollbackApplicationResponse -> Bool
$c/= :: RollbackApplicationResponse -> RollbackApplicationResponse -> Bool
== :: RollbackApplicationResponse -> RollbackApplicationResponse -> Bool
$c== :: RollbackApplicationResponse -> RollbackApplicationResponse -> Bool
Prelude.Eq, ReadPrec [RollbackApplicationResponse]
ReadPrec RollbackApplicationResponse
Int -> ReadS RollbackApplicationResponse
ReadS [RollbackApplicationResponse]
(Int -> ReadS RollbackApplicationResponse)
-> ReadS [RollbackApplicationResponse]
-> ReadPrec RollbackApplicationResponse
-> ReadPrec [RollbackApplicationResponse]
-> Read RollbackApplicationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RollbackApplicationResponse]
$creadListPrec :: ReadPrec [RollbackApplicationResponse]
readPrec :: ReadPrec RollbackApplicationResponse
$creadPrec :: ReadPrec RollbackApplicationResponse
readList :: ReadS [RollbackApplicationResponse]
$creadList :: ReadS [RollbackApplicationResponse]
readsPrec :: Int -> ReadS RollbackApplicationResponse
$creadsPrec :: Int -> ReadS RollbackApplicationResponse
Prelude.Read, Int -> RollbackApplicationResponse -> ShowS
[RollbackApplicationResponse] -> ShowS
RollbackApplicationResponse -> String
(Int -> RollbackApplicationResponse -> ShowS)
-> (RollbackApplicationResponse -> String)
-> ([RollbackApplicationResponse] -> ShowS)
-> Show RollbackApplicationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RollbackApplicationResponse] -> ShowS
$cshowList :: [RollbackApplicationResponse] -> ShowS
show :: RollbackApplicationResponse -> String
$cshow :: RollbackApplicationResponse -> String
showsPrec :: Int -> RollbackApplicationResponse -> ShowS
$cshowsPrec :: Int -> RollbackApplicationResponse -> ShowS
Prelude.Show, (forall x.
 RollbackApplicationResponse -> Rep RollbackApplicationResponse x)
-> (forall x.
    Rep RollbackApplicationResponse x -> RollbackApplicationResponse)
-> Generic RollbackApplicationResponse
forall x.
Rep RollbackApplicationResponse x -> RollbackApplicationResponse
forall x.
RollbackApplicationResponse -> Rep RollbackApplicationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RollbackApplicationResponse x -> RollbackApplicationResponse
$cfrom :: forall x.
RollbackApplicationResponse -> Rep RollbackApplicationResponse x
Prelude.Generic)

-- |
-- Create a value of 'RollbackApplicationResponse' 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', 'rollbackApplicationResponse_httpStatus' - The response's http status code.
--
-- 'applicationDetail', 'rollbackApplicationResponse_applicationDetail' - Undocumented member.
newRollbackApplicationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'applicationDetail'
  ApplicationDetail ->
  RollbackApplicationResponse
newRollbackApplicationResponse :: Int -> ApplicationDetail -> RollbackApplicationResponse
newRollbackApplicationResponse
  Int
pHttpStatus_
  ApplicationDetail
pApplicationDetail_ =
    RollbackApplicationResponse' :: Int -> ApplicationDetail -> RollbackApplicationResponse
RollbackApplicationResponse'
      { $sel:httpStatus:RollbackApplicationResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:applicationDetail:RollbackApplicationResponse' :: ApplicationDetail
applicationDetail = ApplicationDetail
pApplicationDetail_
      }

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

-- | Undocumented member.
rollbackApplicationResponse_applicationDetail :: Lens.Lens' RollbackApplicationResponse ApplicationDetail
rollbackApplicationResponse_applicationDetail :: (ApplicationDetail -> f ApplicationDetail)
-> RollbackApplicationResponse -> f RollbackApplicationResponse
rollbackApplicationResponse_applicationDetail = (RollbackApplicationResponse -> ApplicationDetail)
-> (RollbackApplicationResponse
    -> ApplicationDetail -> RollbackApplicationResponse)
-> Lens
     RollbackApplicationResponse
     RollbackApplicationResponse
     ApplicationDetail
     ApplicationDetail
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RollbackApplicationResponse' {ApplicationDetail
applicationDetail :: ApplicationDetail
$sel:applicationDetail:RollbackApplicationResponse' :: RollbackApplicationResponse -> ApplicationDetail
applicationDetail} -> ApplicationDetail
applicationDetail) (\s :: RollbackApplicationResponse
s@RollbackApplicationResponse' {} ApplicationDetail
a -> RollbackApplicationResponse
s {$sel:applicationDetail:RollbackApplicationResponse' :: ApplicationDetail
applicationDetail = ApplicationDetail
a} :: RollbackApplicationResponse)

instance Prelude.NFData RollbackApplicationResponse