{-# 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.GetAutoSnapshots
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the available automatic snapshots for an instance or disk. For
-- more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-configuring-automatic-snapshots Amazon Lightsail Developer Guide>.
module Amazonka.Lightsail.GetAutoSnapshots
  ( -- * Creating a Request
    GetAutoSnapshots (..),
    newGetAutoSnapshots,

    -- * Request Lenses
    getAutoSnapshots_resourceName,

    -- * Destructuring the Response
    GetAutoSnapshotsResponse (..),
    newGetAutoSnapshotsResponse,

    -- * Response Lenses
    getAutoSnapshotsResponse_autoSnapshots,
    getAutoSnapshotsResponse_resourceName,
    getAutoSnapshotsResponse_resourceType,
    getAutoSnapshotsResponse_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:/ 'newGetAutoSnapshots' smart constructor.
data GetAutoSnapshots = GetAutoSnapshots'
  { -- | The name of the source instance or disk from which to get automatic
    -- snapshot information.
    GetAutoSnapshots -> Text
resourceName :: Prelude.Text
  }
  deriving (GetAutoSnapshots -> GetAutoSnapshots -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAutoSnapshots -> GetAutoSnapshots -> Bool
$c/= :: GetAutoSnapshots -> GetAutoSnapshots -> Bool
== :: GetAutoSnapshots -> GetAutoSnapshots -> Bool
$c== :: GetAutoSnapshots -> GetAutoSnapshots -> Bool
Prelude.Eq, ReadPrec [GetAutoSnapshots]
ReadPrec GetAutoSnapshots
Int -> ReadS GetAutoSnapshots
ReadS [GetAutoSnapshots]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAutoSnapshots]
$creadListPrec :: ReadPrec [GetAutoSnapshots]
readPrec :: ReadPrec GetAutoSnapshots
$creadPrec :: ReadPrec GetAutoSnapshots
readList :: ReadS [GetAutoSnapshots]
$creadList :: ReadS [GetAutoSnapshots]
readsPrec :: Int -> ReadS GetAutoSnapshots
$creadsPrec :: Int -> ReadS GetAutoSnapshots
Prelude.Read, Int -> GetAutoSnapshots -> ShowS
[GetAutoSnapshots] -> ShowS
GetAutoSnapshots -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAutoSnapshots] -> ShowS
$cshowList :: [GetAutoSnapshots] -> ShowS
show :: GetAutoSnapshots -> String
$cshow :: GetAutoSnapshots -> String
showsPrec :: Int -> GetAutoSnapshots -> ShowS
$cshowsPrec :: Int -> GetAutoSnapshots -> ShowS
Prelude.Show, forall x. Rep GetAutoSnapshots x -> GetAutoSnapshots
forall x. GetAutoSnapshots -> Rep GetAutoSnapshots x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetAutoSnapshots x -> GetAutoSnapshots
$cfrom :: forall x. GetAutoSnapshots -> Rep GetAutoSnapshots x
Prelude.Generic)

-- |
-- Create a value of 'GetAutoSnapshots' 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:
--
-- 'resourceName', 'getAutoSnapshots_resourceName' - The name of the source instance or disk from which to get automatic
-- snapshot information.
newGetAutoSnapshots ::
  -- | 'resourceName'
  Prelude.Text ->
  GetAutoSnapshots
newGetAutoSnapshots :: Text -> GetAutoSnapshots
newGetAutoSnapshots Text
pResourceName_ =
  GetAutoSnapshots' {$sel:resourceName:GetAutoSnapshots' :: Text
resourceName = Text
pResourceName_}

-- | The name of the source instance or disk from which to get automatic
-- snapshot information.
getAutoSnapshots_resourceName :: Lens.Lens' GetAutoSnapshots Prelude.Text
getAutoSnapshots_resourceName :: Lens' GetAutoSnapshots Text
getAutoSnapshots_resourceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAutoSnapshots' {Text
resourceName :: Text
$sel:resourceName:GetAutoSnapshots' :: GetAutoSnapshots -> Text
resourceName} -> Text
resourceName) (\s :: GetAutoSnapshots
s@GetAutoSnapshots' {} Text
a -> GetAutoSnapshots
s {$sel:resourceName:GetAutoSnapshots' :: Text
resourceName = Text
a} :: GetAutoSnapshots)

instance Core.AWSRequest GetAutoSnapshots where
  type
    AWSResponse GetAutoSnapshots =
      GetAutoSnapshotsResponse
  request :: (Service -> Service)
-> GetAutoSnapshots -> Request GetAutoSnapshots
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 GetAutoSnapshots
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAutoSnapshots)))
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 [AutoSnapshotDetails]
-> Maybe Text
-> Maybe ResourceType
-> Int
-> GetAutoSnapshotsResponse
GetAutoSnapshotsResponse'
            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
"autoSnapshots" 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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"resourceName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"resourceType")
            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 GetAutoSnapshots where
  hashWithSalt :: Int -> GetAutoSnapshots -> Int
hashWithSalt Int
_salt GetAutoSnapshots' {Text
resourceName :: Text
$sel:resourceName:GetAutoSnapshots' :: GetAutoSnapshots -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceName

instance Prelude.NFData GetAutoSnapshots where
  rnf :: GetAutoSnapshots -> ()
rnf GetAutoSnapshots' {Text
resourceName :: Text
$sel:resourceName:GetAutoSnapshots' :: GetAutoSnapshots -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
resourceName

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

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

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

-- | /See:/ 'newGetAutoSnapshotsResponse' smart constructor.
data GetAutoSnapshotsResponse = GetAutoSnapshotsResponse'
  { -- | An array of objects that describe the automatic snapshots that are
    -- available for the specified source instance or disk.
    GetAutoSnapshotsResponse -> Maybe [AutoSnapshotDetails]
autoSnapshots :: Prelude.Maybe [AutoSnapshotDetails],
    -- | The name of the source instance or disk for the automatic snapshots.
    GetAutoSnapshotsResponse -> Maybe Text
resourceName :: Prelude.Maybe Prelude.Text,
    -- | The resource type (e.g., @Instance@ or @Disk@).
    GetAutoSnapshotsResponse -> Maybe ResourceType
resourceType :: Prelude.Maybe ResourceType,
    -- | The response's http status code.
    GetAutoSnapshotsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetAutoSnapshotsResponse -> GetAutoSnapshotsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAutoSnapshotsResponse -> GetAutoSnapshotsResponse -> Bool
$c/= :: GetAutoSnapshotsResponse -> GetAutoSnapshotsResponse -> Bool
== :: GetAutoSnapshotsResponse -> GetAutoSnapshotsResponse -> Bool
$c== :: GetAutoSnapshotsResponse -> GetAutoSnapshotsResponse -> Bool
Prelude.Eq, ReadPrec [GetAutoSnapshotsResponse]
ReadPrec GetAutoSnapshotsResponse
Int -> ReadS GetAutoSnapshotsResponse
ReadS [GetAutoSnapshotsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAutoSnapshotsResponse]
$creadListPrec :: ReadPrec [GetAutoSnapshotsResponse]
readPrec :: ReadPrec GetAutoSnapshotsResponse
$creadPrec :: ReadPrec GetAutoSnapshotsResponse
readList :: ReadS [GetAutoSnapshotsResponse]
$creadList :: ReadS [GetAutoSnapshotsResponse]
readsPrec :: Int -> ReadS GetAutoSnapshotsResponse
$creadsPrec :: Int -> ReadS GetAutoSnapshotsResponse
Prelude.Read, Int -> GetAutoSnapshotsResponse -> ShowS
[GetAutoSnapshotsResponse] -> ShowS
GetAutoSnapshotsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAutoSnapshotsResponse] -> ShowS
$cshowList :: [GetAutoSnapshotsResponse] -> ShowS
show :: GetAutoSnapshotsResponse -> String
$cshow :: GetAutoSnapshotsResponse -> String
showsPrec :: Int -> GetAutoSnapshotsResponse -> ShowS
$cshowsPrec :: Int -> GetAutoSnapshotsResponse -> ShowS
Prelude.Show, forall x.
Rep GetAutoSnapshotsResponse x -> GetAutoSnapshotsResponse
forall x.
GetAutoSnapshotsResponse -> Rep GetAutoSnapshotsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetAutoSnapshotsResponse x -> GetAutoSnapshotsResponse
$cfrom :: forall x.
GetAutoSnapshotsResponse -> Rep GetAutoSnapshotsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAutoSnapshotsResponse' 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:
--
-- 'autoSnapshots', 'getAutoSnapshotsResponse_autoSnapshots' - An array of objects that describe the automatic snapshots that are
-- available for the specified source instance or disk.
--
-- 'resourceName', 'getAutoSnapshotsResponse_resourceName' - The name of the source instance or disk for the automatic snapshots.
--
-- 'resourceType', 'getAutoSnapshotsResponse_resourceType' - The resource type (e.g., @Instance@ or @Disk@).
--
-- 'httpStatus', 'getAutoSnapshotsResponse_httpStatus' - The response's http status code.
newGetAutoSnapshotsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetAutoSnapshotsResponse
newGetAutoSnapshotsResponse :: Int -> GetAutoSnapshotsResponse
newGetAutoSnapshotsResponse Int
pHttpStatus_ =
  GetAutoSnapshotsResponse'
    { $sel:autoSnapshots:GetAutoSnapshotsResponse' :: Maybe [AutoSnapshotDetails]
autoSnapshots =
        forall a. Maybe a
Prelude.Nothing,
      $sel:resourceName:GetAutoSnapshotsResponse' :: Maybe Text
resourceName = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:GetAutoSnapshotsResponse' :: Maybe ResourceType
resourceType = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetAutoSnapshotsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the automatic snapshots that are
-- available for the specified source instance or disk.
getAutoSnapshotsResponse_autoSnapshots :: Lens.Lens' GetAutoSnapshotsResponse (Prelude.Maybe [AutoSnapshotDetails])
getAutoSnapshotsResponse_autoSnapshots :: Lens' GetAutoSnapshotsResponse (Maybe [AutoSnapshotDetails])
getAutoSnapshotsResponse_autoSnapshots = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAutoSnapshotsResponse' {Maybe [AutoSnapshotDetails]
autoSnapshots :: Maybe [AutoSnapshotDetails]
$sel:autoSnapshots:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe [AutoSnapshotDetails]
autoSnapshots} -> Maybe [AutoSnapshotDetails]
autoSnapshots) (\s :: GetAutoSnapshotsResponse
s@GetAutoSnapshotsResponse' {} Maybe [AutoSnapshotDetails]
a -> GetAutoSnapshotsResponse
s {$sel:autoSnapshots:GetAutoSnapshotsResponse' :: Maybe [AutoSnapshotDetails]
autoSnapshots = Maybe [AutoSnapshotDetails]
a} :: GetAutoSnapshotsResponse) 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 name of the source instance or disk for the automatic snapshots.
getAutoSnapshotsResponse_resourceName :: Lens.Lens' GetAutoSnapshotsResponse (Prelude.Maybe Prelude.Text)
getAutoSnapshotsResponse_resourceName :: Lens' GetAutoSnapshotsResponse (Maybe Text)
getAutoSnapshotsResponse_resourceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAutoSnapshotsResponse' {Maybe Text
resourceName :: Maybe Text
$sel:resourceName:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe Text
resourceName} -> Maybe Text
resourceName) (\s :: GetAutoSnapshotsResponse
s@GetAutoSnapshotsResponse' {} Maybe Text
a -> GetAutoSnapshotsResponse
s {$sel:resourceName:GetAutoSnapshotsResponse' :: Maybe Text
resourceName = Maybe Text
a} :: GetAutoSnapshotsResponse)

-- | The resource type (e.g., @Instance@ or @Disk@).
getAutoSnapshotsResponse_resourceType :: Lens.Lens' GetAutoSnapshotsResponse (Prelude.Maybe ResourceType)
getAutoSnapshotsResponse_resourceType :: Lens' GetAutoSnapshotsResponse (Maybe ResourceType)
getAutoSnapshotsResponse_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAutoSnapshotsResponse' {Maybe ResourceType
resourceType :: Maybe ResourceType
$sel:resourceType:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe ResourceType
resourceType} -> Maybe ResourceType
resourceType) (\s :: GetAutoSnapshotsResponse
s@GetAutoSnapshotsResponse' {} Maybe ResourceType
a -> GetAutoSnapshotsResponse
s {$sel:resourceType:GetAutoSnapshotsResponse' :: Maybe ResourceType
resourceType = Maybe ResourceType
a} :: GetAutoSnapshotsResponse)

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

instance Prelude.NFData GetAutoSnapshotsResponse where
  rnf :: GetAutoSnapshotsResponse -> ()
rnf GetAutoSnapshotsResponse' {Int
Maybe [AutoSnapshotDetails]
Maybe Text
Maybe ResourceType
httpStatus :: Int
resourceType :: Maybe ResourceType
resourceName :: Maybe Text
autoSnapshots :: Maybe [AutoSnapshotDetails]
$sel:httpStatus:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Int
$sel:resourceType:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe ResourceType
$sel:resourceName:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe Text
$sel:autoSnapshots:GetAutoSnapshotsResponse' :: GetAutoSnapshotsResponse -> Maybe [AutoSnapshotDetails]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [AutoSnapshotDetails]
autoSnapshots
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ResourceType
resourceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus