{-# 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.Lightsail.StopRelationalDatabase
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops a specific database that is currently running in Amazon Lightsail.
--
-- The @stop relational database@ operation supports tag-based access
-- control via resource tags applied to the resource identified by
-- relationalDatabaseName. For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.StopRelationalDatabase
  ( -- * Creating a Request
    StopRelationalDatabase (..),
    newStopRelationalDatabase,

    -- * Request Lenses
    stopRelationalDatabase_relationalDatabaseSnapshotName,
    stopRelationalDatabase_relationalDatabaseName,

    -- * Destructuring the Response
    StopRelationalDatabaseResponse (..),
    newStopRelationalDatabaseResponse,

    -- * Response Lenses
    stopRelationalDatabaseResponse_operations,
    stopRelationalDatabaseResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStopRelationalDatabase' smart constructor.
data StopRelationalDatabase = StopRelationalDatabase'
  { -- | The name of your new database snapshot to be created before stopping
    -- your database.
    StopRelationalDatabase -> Maybe Text
relationalDatabaseSnapshotName :: Prelude.Maybe Prelude.Text,
    -- | The name of your database to stop.
    StopRelationalDatabase -> Text
relationalDatabaseName :: Prelude.Text
  }
  deriving (StopRelationalDatabase -> StopRelationalDatabase -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopRelationalDatabase -> StopRelationalDatabase -> Bool
$c/= :: StopRelationalDatabase -> StopRelationalDatabase -> Bool
== :: StopRelationalDatabase -> StopRelationalDatabase -> Bool
$c== :: StopRelationalDatabase -> StopRelationalDatabase -> Bool
Prelude.Eq, ReadPrec [StopRelationalDatabase]
ReadPrec StopRelationalDatabase
Int -> ReadS StopRelationalDatabase
ReadS [StopRelationalDatabase]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopRelationalDatabase]
$creadListPrec :: ReadPrec [StopRelationalDatabase]
readPrec :: ReadPrec StopRelationalDatabase
$creadPrec :: ReadPrec StopRelationalDatabase
readList :: ReadS [StopRelationalDatabase]
$creadList :: ReadS [StopRelationalDatabase]
readsPrec :: Int -> ReadS StopRelationalDatabase
$creadsPrec :: Int -> ReadS StopRelationalDatabase
Prelude.Read, Int -> StopRelationalDatabase -> ShowS
[StopRelationalDatabase] -> ShowS
StopRelationalDatabase -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopRelationalDatabase] -> ShowS
$cshowList :: [StopRelationalDatabase] -> ShowS
show :: StopRelationalDatabase -> String
$cshow :: StopRelationalDatabase -> String
showsPrec :: Int -> StopRelationalDatabase -> ShowS
$cshowsPrec :: Int -> StopRelationalDatabase -> ShowS
Prelude.Show, forall x. Rep StopRelationalDatabase x -> StopRelationalDatabase
forall x. StopRelationalDatabase -> Rep StopRelationalDatabase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopRelationalDatabase x -> StopRelationalDatabase
$cfrom :: forall x. StopRelationalDatabase -> Rep StopRelationalDatabase x
Prelude.Generic)

-- |
-- Create a value of 'StopRelationalDatabase' 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:
--
-- 'relationalDatabaseSnapshotName', 'stopRelationalDatabase_relationalDatabaseSnapshotName' - The name of your new database snapshot to be created before stopping
-- your database.
--
-- 'relationalDatabaseName', 'stopRelationalDatabase_relationalDatabaseName' - The name of your database to stop.
newStopRelationalDatabase ::
  -- | 'relationalDatabaseName'
  Prelude.Text ->
  StopRelationalDatabase
newStopRelationalDatabase :: Text -> StopRelationalDatabase
newStopRelationalDatabase Text
pRelationalDatabaseName_ =
  StopRelationalDatabase'
    { $sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: Maybe Text
relationalDatabaseSnapshotName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:relationalDatabaseName:StopRelationalDatabase' :: Text
relationalDatabaseName = Text
pRelationalDatabaseName_
    }

-- | The name of your new database snapshot to be created before stopping
-- your database.
stopRelationalDatabase_relationalDatabaseSnapshotName :: Lens.Lens' StopRelationalDatabase (Prelude.Maybe Prelude.Text)
stopRelationalDatabase_relationalDatabaseSnapshotName :: Lens' StopRelationalDatabase (Maybe Text)
stopRelationalDatabase_relationalDatabaseSnapshotName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopRelationalDatabase' {Maybe Text
relationalDatabaseSnapshotName :: Maybe Text
$sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: StopRelationalDatabase -> Maybe Text
relationalDatabaseSnapshotName} -> Maybe Text
relationalDatabaseSnapshotName) (\s :: StopRelationalDatabase
s@StopRelationalDatabase' {} Maybe Text
a -> StopRelationalDatabase
s {$sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: Maybe Text
relationalDatabaseSnapshotName = Maybe Text
a} :: StopRelationalDatabase)

-- | The name of your database to stop.
stopRelationalDatabase_relationalDatabaseName :: Lens.Lens' StopRelationalDatabase Prelude.Text
stopRelationalDatabase_relationalDatabaseName :: Lens' StopRelationalDatabase Text
stopRelationalDatabase_relationalDatabaseName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopRelationalDatabase' {Text
relationalDatabaseName :: Text
$sel:relationalDatabaseName:StopRelationalDatabase' :: StopRelationalDatabase -> Text
relationalDatabaseName} -> Text
relationalDatabaseName) (\s :: StopRelationalDatabase
s@StopRelationalDatabase' {} Text
a -> StopRelationalDatabase
s {$sel:relationalDatabaseName:StopRelationalDatabase' :: Text
relationalDatabaseName = Text
a} :: StopRelationalDatabase)

instance Core.AWSRequest StopRelationalDatabase where
  type
    AWSResponse StopRelationalDatabase =
      StopRelationalDatabaseResponse
  request :: (Service -> Service)
-> StopRelationalDatabase -> Request StopRelationalDatabase
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 StopRelationalDatabase
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StopRelationalDatabase)))
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 ->
          Maybe [Operation] -> Int -> StopRelationalDatabaseResponse
StopRelationalDatabaseResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable StopRelationalDatabase where
  hashWithSalt :: Int -> StopRelationalDatabase -> Int
hashWithSalt Int
_salt StopRelationalDatabase' {Maybe Text
Text
relationalDatabaseName :: Text
relationalDatabaseSnapshotName :: Maybe Text
$sel:relationalDatabaseName:StopRelationalDatabase' :: StopRelationalDatabase -> Text
$sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: StopRelationalDatabase -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
relationalDatabaseSnapshotName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
relationalDatabaseName

instance Prelude.NFData StopRelationalDatabase where
  rnf :: StopRelationalDatabase -> ()
rnf StopRelationalDatabase' {Maybe Text
Text
relationalDatabaseName :: Text
relationalDatabaseSnapshotName :: Maybe Text
$sel:relationalDatabaseName:StopRelationalDatabase' :: StopRelationalDatabase -> Text
$sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: StopRelationalDatabase -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
relationalDatabaseSnapshotName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
relationalDatabaseName

instance Data.ToHeaders StopRelationalDatabase where
  toHeaders :: StopRelationalDatabase -> 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
"Lightsail_20161128.StopRelationalDatabase" ::
                          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 StopRelationalDatabase where
  toJSON :: StopRelationalDatabase -> Value
toJSON StopRelationalDatabase' {Maybe Text
Text
relationalDatabaseName :: Text
relationalDatabaseSnapshotName :: Maybe Text
$sel:relationalDatabaseName:StopRelationalDatabase' :: StopRelationalDatabase -> Text
$sel:relationalDatabaseSnapshotName:StopRelationalDatabase' :: StopRelationalDatabase -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"relationalDatabaseSnapshotName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
relationalDatabaseSnapshotName,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"relationalDatabaseName"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
relationalDatabaseName
              )
          ]
      )

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

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

-- | /See:/ 'newStopRelationalDatabaseResponse' smart constructor.
data StopRelationalDatabaseResponse = StopRelationalDatabaseResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    StopRelationalDatabaseResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    StopRelationalDatabaseResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopRelationalDatabaseResponse
-> StopRelationalDatabaseResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopRelationalDatabaseResponse
-> StopRelationalDatabaseResponse -> Bool
$c/= :: StopRelationalDatabaseResponse
-> StopRelationalDatabaseResponse -> Bool
== :: StopRelationalDatabaseResponse
-> StopRelationalDatabaseResponse -> Bool
$c== :: StopRelationalDatabaseResponse
-> StopRelationalDatabaseResponse -> Bool
Prelude.Eq, ReadPrec [StopRelationalDatabaseResponse]
ReadPrec StopRelationalDatabaseResponse
Int -> ReadS StopRelationalDatabaseResponse
ReadS [StopRelationalDatabaseResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopRelationalDatabaseResponse]
$creadListPrec :: ReadPrec [StopRelationalDatabaseResponse]
readPrec :: ReadPrec StopRelationalDatabaseResponse
$creadPrec :: ReadPrec StopRelationalDatabaseResponse
readList :: ReadS [StopRelationalDatabaseResponse]
$creadList :: ReadS [StopRelationalDatabaseResponse]
readsPrec :: Int -> ReadS StopRelationalDatabaseResponse
$creadsPrec :: Int -> ReadS StopRelationalDatabaseResponse
Prelude.Read, Int -> StopRelationalDatabaseResponse -> ShowS
[StopRelationalDatabaseResponse] -> ShowS
StopRelationalDatabaseResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopRelationalDatabaseResponse] -> ShowS
$cshowList :: [StopRelationalDatabaseResponse] -> ShowS
show :: StopRelationalDatabaseResponse -> String
$cshow :: StopRelationalDatabaseResponse -> String
showsPrec :: Int -> StopRelationalDatabaseResponse -> ShowS
$cshowsPrec :: Int -> StopRelationalDatabaseResponse -> ShowS
Prelude.Show, forall x.
Rep StopRelationalDatabaseResponse x
-> StopRelationalDatabaseResponse
forall x.
StopRelationalDatabaseResponse
-> Rep StopRelationalDatabaseResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StopRelationalDatabaseResponse x
-> StopRelationalDatabaseResponse
$cfrom :: forall x.
StopRelationalDatabaseResponse
-> Rep StopRelationalDatabaseResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopRelationalDatabaseResponse' 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:
--
-- 'operations', 'stopRelationalDatabaseResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'stopRelationalDatabaseResponse_httpStatus' - The response's http status code.
newStopRelationalDatabaseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopRelationalDatabaseResponse
newStopRelationalDatabaseResponse :: Int -> StopRelationalDatabaseResponse
newStopRelationalDatabaseResponse Int
pHttpStatus_ =
  StopRelationalDatabaseResponse'
    { $sel:operations:StopRelationalDatabaseResponse' :: Maybe [Operation]
operations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopRelationalDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
stopRelationalDatabaseResponse_operations :: Lens.Lens' StopRelationalDatabaseResponse (Prelude.Maybe [Operation])
stopRelationalDatabaseResponse_operations :: Lens' StopRelationalDatabaseResponse (Maybe [Operation])
stopRelationalDatabaseResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopRelationalDatabaseResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:StopRelationalDatabaseResponse' :: StopRelationalDatabaseResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: StopRelationalDatabaseResponse
s@StopRelationalDatabaseResponse' {} Maybe [Operation]
a -> StopRelationalDatabaseResponse
s {$sel:operations:StopRelationalDatabaseResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: StopRelationalDatabaseResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    StopRelationalDatabaseResponse
  where
  rnf :: StopRelationalDatabaseResponse -> ()
rnf StopRelationalDatabaseResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:StopRelationalDatabaseResponse' :: StopRelationalDatabaseResponse -> Int
$sel:operations:StopRelationalDatabaseResponse' :: StopRelationalDatabaseResponse -> Maybe [Operation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus