{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KinesisAnalyticsV2.Types
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
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]
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
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. 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'
      { $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 :: Lens' RollbackApplication Text
rollbackApplication_applicationName = 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 :: Lens' RollbackApplication Natural
rollbackApplication_currentApplicationVersionId = 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 :: (Service -> Service)
-> RollbackApplication -> Request RollbackApplication
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 RollbackApplication
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RollbackApplication)))
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 -> ApplicationDetail -> RollbackApplicationResponse
RollbackApplicationResponse'
            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
"ApplicationDetail")
      )

instance Prelude.Hashable RollbackApplication where
  hashWithSalt :: Int -> RollbackApplication -> Int
hashWithSalt Int
_salt RollbackApplication' {Natural
Text
currentApplicationVersionId :: Natural
applicationName :: Text
$sel:currentApplicationVersionId:RollbackApplication' :: RollbackApplication -> Natural
$sel:applicationName:RollbackApplication' :: RollbackApplication -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
applicationName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
currentApplicationVersionId

instance Prelude.NFData RollbackApplication where
  rnf :: RollbackApplication -> ()
rnf RollbackApplication' {Natural
Text
currentApplicationVersionId :: Natural
applicationName :: Text
$sel:currentApplicationVersionId:RollbackApplication' :: RollbackApplication -> Natural
$sel:applicationName:RollbackApplication' :: RollbackApplication -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
applicationName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
currentApplicationVersionId

instance Data.ToHeaders RollbackApplication where
  toHeaders :: RollbackApplication -> 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
"KinesisAnalytics_20180523.RollbackApplication" ::
                          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 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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ApplicationName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
applicationName),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"CurrentApplicationVersionId"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
currentApplicationVersionId
              )
          ]
      )

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

instance Data.ToQuery RollbackApplication where
  toQuery :: RollbackApplication -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
      { $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 :: Lens' RollbackApplicationResponse Int
rollbackApplicationResponse_httpStatus = 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 :: Lens' RollbackApplicationResponse ApplicationDetail
rollbackApplicationResponse_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 where
  rnf :: RollbackApplicationResponse -> ()
rnf RollbackApplicationResponse' {Int
ApplicationDetail
applicationDetail :: ApplicationDetail
httpStatus :: Int
$sel:applicationDetail:RollbackApplicationResponse' :: RollbackApplicationResponse -> ApplicationDetail
$sel:httpStatus:RollbackApplicationResponse' :: RollbackApplicationResponse -> 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 ApplicationDetail
applicationDetail