{-# 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.Backup.DescribeProtectedResource
-- 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 information about a saved resource, including the last time it
-- was backed up, its Amazon Resource Name (ARN), and the Amazon Web
-- Services service type of the saved resource.
module Amazonka.Backup.DescribeProtectedResource
  ( -- * Creating a Request
    DescribeProtectedResource (..),
    newDescribeProtectedResource,

    -- * Request Lenses
    describeProtectedResource_resourceArn,

    -- * Destructuring the Response
    DescribeProtectedResourceResponse (..),
    newDescribeProtectedResourceResponse,

    -- * Response Lenses
    describeProtectedResourceResponse_lastBackupTime,
    describeProtectedResourceResponse_resourceArn,
    describeProtectedResourceResponse_resourceType,
    describeProtectedResourceResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDescribeProtectedResource' smart constructor.
data DescribeProtectedResource = DescribeProtectedResource'
  { -- | An Amazon Resource Name (ARN) that uniquely identifies a resource. The
    -- format of the ARN depends on the resource type.
    DescribeProtectedResource -> Text
resourceArn :: Prelude.Text
  }
  deriving (DescribeProtectedResource -> DescribeProtectedResource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeProtectedResource -> DescribeProtectedResource -> Bool
$c/= :: DescribeProtectedResource -> DescribeProtectedResource -> Bool
== :: DescribeProtectedResource -> DescribeProtectedResource -> Bool
$c== :: DescribeProtectedResource -> DescribeProtectedResource -> Bool
Prelude.Eq, ReadPrec [DescribeProtectedResource]
ReadPrec DescribeProtectedResource
Int -> ReadS DescribeProtectedResource
ReadS [DescribeProtectedResource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeProtectedResource]
$creadListPrec :: ReadPrec [DescribeProtectedResource]
readPrec :: ReadPrec DescribeProtectedResource
$creadPrec :: ReadPrec DescribeProtectedResource
readList :: ReadS [DescribeProtectedResource]
$creadList :: ReadS [DescribeProtectedResource]
readsPrec :: Int -> ReadS DescribeProtectedResource
$creadsPrec :: Int -> ReadS DescribeProtectedResource
Prelude.Read, Int -> DescribeProtectedResource -> ShowS
[DescribeProtectedResource] -> ShowS
DescribeProtectedResource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeProtectedResource] -> ShowS
$cshowList :: [DescribeProtectedResource] -> ShowS
show :: DescribeProtectedResource -> String
$cshow :: DescribeProtectedResource -> String
showsPrec :: Int -> DescribeProtectedResource -> ShowS
$cshowsPrec :: Int -> DescribeProtectedResource -> ShowS
Prelude.Show, forall x.
Rep DescribeProtectedResource x -> DescribeProtectedResource
forall x.
DescribeProtectedResource -> Rep DescribeProtectedResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeProtectedResource x -> DescribeProtectedResource
$cfrom :: forall x.
DescribeProtectedResource -> Rep DescribeProtectedResource x
Prelude.Generic)

-- |
-- Create a value of 'DescribeProtectedResource' 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:
--
-- 'resourceArn', 'describeProtectedResource_resourceArn' - An Amazon Resource Name (ARN) that uniquely identifies a resource. The
-- format of the ARN depends on the resource type.
newDescribeProtectedResource ::
  -- | 'resourceArn'
  Prelude.Text ->
  DescribeProtectedResource
newDescribeProtectedResource :: Text -> DescribeProtectedResource
newDescribeProtectedResource Text
pResourceArn_ =
  DescribeProtectedResource'
    { $sel:resourceArn:DescribeProtectedResource' :: Text
resourceArn =
        Text
pResourceArn_
    }

-- | An Amazon Resource Name (ARN) that uniquely identifies a resource. The
-- format of the ARN depends on the resource type.
describeProtectedResource_resourceArn :: Lens.Lens' DescribeProtectedResource Prelude.Text
describeProtectedResource_resourceArn :: Lens' DescribeProtectedResource Text
describeProtectedResource_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtectedResource' {Text
resourceArn :: Text
$sel:resourceArn:DescribeProtectedResource' :: DescribeProtectedResource -> Text
resourceArn} -> Text
resourceArn) (\s :: DescribeProtectedResource
s@DescribeProtectedResource' {} Text
a -> DescribeProtectedResource
s {$sel:resourceArn:DescribeProtectedResource' :: Text
resourceArn = Text
a} :: DescribeProtectedResource)

instance Core.AWSRequest DescribeProtectedResource where
  type
    AWSResponse DescribeProtectedResource =
      DescribeProtectedResourceResponse
  request :: (Service -> Service)
-> DescribeProtectedResource -> Request DescribeProtectedResource
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy DescribeProtectedResource
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeProtectedResource)))
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 POSIX
-> Maybe Text
-> Maybe Text
-> Int
-> DescribeProtectedResourceResponse
DescribeProtectedResourceResponse'
            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
"LastBackupTime")
            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
"ResourceArn")
            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 DescribeProtectedResource where
  hashWithSalt :: Int -> DescribeProtectedResource -> Int
hashWithSalt Int
_salt DescribeProtectedResource' {Text
resourceArn :: Text
$sel:resourceArn:DescribeProtectedResource' :: DescribeProtectedResource -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceArn

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

instance Data.ToHeaders DescribeProtectedResource where
  toHeaders :: DescribeProtectedResource -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToPath DescribeProtectedResource where
  toPath :: DescribeProtectedResource -> ByteString
toPath DescribeProtectedResource' {Text
resourceArn :: Text
$sel:resourceArn:DescribeProtectedResource' :: DescribeProtectedResource -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/resources/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
resourceArn]

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

-- | /See:/ 'newDescribeProtectedResourceResponse' smart constructor.
data DescribeProtectedResourceResponse = DescribeProtectedResourceResponse'
  { -- | The date and time that a resource was last backed up, in Unix format and
    -- Coordinated Universal Time (UTC). The value of @LastBackupTime@ is
    -- accurate to milliseconds. For example, the value 1516925490.087
    -- represents Friday, January 26, 2018 12:11:30.087 AM.
    DescribeProtectedResourceResponse -> Maybe POSIX
lastBackupTime :: Prelude.Maybe Data.POSIX,
    -- | An ARN that uniquely identifies a resource. The format of the ARN
    -- depends on the resource type.
    DescribeProtectedResourceResponse -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The type of Amazon Web Services resource saved as a recovery point; for
    -- example, an Amazon EBS volume or an Amazon RDS database.
    DescribeProtectedResourceResponse -> Maybe Text
resourceType :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DescribeProtectedResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeProtectedResourceResponse
-> DescribeProtectedResourceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeProtectedResourceResponse
-> DescribeProtectedResourceResponse -> Bool
$c/= :: DescribeProtectedResourceResponse
-> DescribeProtectedResourceResponse -> Bool
== :: DescribeProtectedResourceResponse
-> DescribeProtectedResourceResponse -> Bool
$c== :: DescribeProtectedResourceResponse
-> DescribeProtectedResourceResponse -> Bool
Prelude.Eq, ReadPrec [DescribeProtectedResourceResponse]
ReadPrec DescribeProtectedResourceResponse
Int -> ReadS DescribeProtectedResourceResponse
ReadS [DescribeProtectedResourceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeProtectedResourceResponse]
$creadListPrec :: ReadPrec [DescribeProtectedResourceResponse]
readPrec :: ReadPrec DescribeProtectedResourceResponse
$creadPrec :: ReadPrec DescribeProtectedResourceResponse
readList :: ReadS [DescribeProtectedResourceResponse]
$creadList :: ReadS [DescribeProtectedResourceResponse]
readsPrec :: Int -> ReadS DescribeProtectedResourceResponse
$creadsPrec :: Int -> ReadS DescribeProtectedResourceResponse
Prelude.Read, Int -> DescribeProtectedResourceResponse -> ShowS
[DescribeProtectedResourceResponse] -> ShowS
DescribeProtectedResourceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeProtectedResourceResponse] -> ShowS
$cshowList :: [DescribeProtectedResourceResponse] -> ShowS
show :: DescribeProtectedResourceResponse -> String
$cshow :: DescribeProtectedResourceResponse -> String
showsPrec :: Int -> DescribeProtectedResourceResponse -> ShowS
$cshowsPrec :: Int -> DescribeProtectedResourceResponse -> ShowS
Prelude.Show, forall x.
Rep DescribeProtectedResourceResponse x
-> DescribeProtectedResourceResponse
forall x.
DescribeProtectedResourceResponse
-> Rep DescribeProtectedResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeProtectedResourceResponse x
-> DescribeProtectedResourceResponse
$cfrom :: forall x.
DescribeProtectedResourceResponse
-> Rep DescribeProtectedResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeProtectedResourceResponse' 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:
--
-- 'lastBackupTime', 'describeProtectedResourceResponse_lastBackupTime' - The date and time that a resource was last backed up, in Unix format and
-- Coordinated Universal Time (UTC). The value of @LastBackupTime@ is
-- accurate to milliseconds. For example, the value 1516925490.087
-- represents Friday, January 26, 2018 12:11:30.087 AM.
--
-- 'resourceArn', 'describeProtectedResourceResponse_resourceArn' - An ARN that uniquely identifies a resource. The format of the ARN
-- depends on the resource type.
--
-- 'resourceType', 'describeProtectedResourceResponse_resourceType' - The type of Amazon Web Services resource saved as a recovery point; for
-- example, an Amazon EBS volume or an Amazon RDS database.
--
-- 'httpStatus', 'describeProtectedResourceResponse_httpStatus' - The response's http status code.
newDescribeProtectedResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeProtectedResourceResponse
newDescribeProtectedResourceResponse :: Int -> DescribeProtectedResourceResponse
newDescribeProtectedResourceResponse Int
pHttpStatus_ =
  DescribeProtectedResourceResponse'
    { $sel:lastBackupTime:DescribeProtectedResourceResponse' :: Maybe POSIX
lastBackupTime =
        forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:DescribeProtectedResourceResponse' :: Maybe Text
resourceArn = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:DescribeProtectedResourceResponse' :: Maybe Text
resourceType = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeProtectedResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The date and time that a resource was last backed up, in Unix format and
-- Coordinated Universal Time (UTC). The value of @LastBackupTime@ is
-- accurate to milliseconds. For example, the value 1516925490.087
-- represents Friday, January 26, 2018 12:11:30.087 AM.
describeProtectedResourceResponse_lastBackupTime :: Lens.Lens' DescribeProtectedResourceResponse (Prelude.Maybe Prelude.UTCTime)
describeProtectedResourceResponse_lastBackupTime :: Lens' DescribeProtectedResourceResponse (Maybe UTCTime)
describeProtectedResourceResponse_lastBackupTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtectedResourceResponse' {Maybe POSIX
lastBackupTime :: Maybe POSIX
$sel:lastBackupTime:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe POSIX
lastBackupTime} -> Maybe POSIX
lastBackupTime) (\s :: DescribeProtectedResourceResponse
s@DescribeProtectedResourceResponse' {} Maybe POSIX
a -> DescribeProtectedResourceResponse
s {$sel:lastBackupTime:DescribeProtectedResourceResponse' :: Maybe POSIX
lastBackupTime = Maybe POSIX
a} :: DescribeProtectedResourceResponse) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | An ARN that uniquely identifies a resource. The format of the ARN
-- depends on the resource type.
describeProtectedResourceResponse_resourceArn :: Lens.Lens' DescribeProtectedResourceResponse (Prelude.Maybe Prelude.Text)
describeProtectedResourceResponse_resourceArn :: Lens' DescribeProtectedResourceResponse (Maybe Text)
describeProtectedResourceResponse_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtectedResourceResponse' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: DescribeProtectedResourceResponse
s@DescribeProtectedResourceResponse' {} Maybe Text
a -> DescribeProtectedResourceResponse
s {$sel:resourceArn:DescribeProtectedResourceResponse' :: Maybe Text
resourceArn = Maybe Text
a} :: DescribeProtectedResourceResponse)

-- | The type of Amazon Web Services resource saved as a recovery point; for
-- example, an Amazon EBS volume or an Amazon RDS database.
describeProtectedResourceResponse_resourceType :: Lens.Lens' DescribeProtectedResourceResponse (Prelude.Maybe Prelude.Text)
describeProtectedResourceResponse_resourceType :: Lens' DescribeProtectedResourceResponse (Maybe Text)
describeProtectedResourceResponse_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtectedResourceResponse' {Maybe Text
resourceType :: Maybe Text
$sel:resourceType:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe Text
resourceType} -> Maybe Text
resourceType) (\s :: DescribeProtectedResourceResponse
s@DescribeProtectedResourceResponse' {} Maybe Text
a -> DescribeProtectedResourceResponse
s {$sel:resourceType:DescribeProtectedResourceResponse' :: Maybe Text
resourceType = Maybe Text
a} :: DescribeProtectedResourceResponse)

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

instance
  Prelude.NFData
    DescribeProtectedResourceResponse
  where
  rnf :: DescribeProtectedResourceResponse -> ()
rnf DescribeProtectedResourceResponse' {Int
Maybe Text
Maybe POSIX
httpStatus :: Int
resourceType :: Maybe Text
resourceArn :: Maybe Text
lastBackupTime :: Maybe POSIX
$sel:httpStatus:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Int
$sel:resourceType:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe Text
$sel:resourceArn:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe Text
$sel:lastBackupTime:DescribeProtectedResourceResponse' :: DescribeProtectedResourceResponse -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastBackupTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus