{-# 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.ServiceCatalogAppRegistry.SyncResource
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Syncs the resource with current AppRegistry records.
--
-- Specifically, the resource’s AppRegistry system tags sync with its
-- associated application. We remove the resource\'s AppRegistry system
-- tags if it does not associate with the application. The caller must have
-- permissions to read and update the resource.
module Amazonka.ServiceCatalogAppRegistry.SyncResource
  ( -- * Creating a Request
    SyncResource (..),
    newSyncResource,

    -- * Request Lenses
    syncResource_resourceType,
    syncResource_resource,

    -- * Destructuring the Response
    SyncResourceResponse (..),
    newSyncResourceResponse,

    -- * Response Lenses
    syncResourceResponse_actionTaken,
    syncResourceResponse_applicationArn,
    syncResourceResponse_resourceArn,
    syncResourceResponse_httpStatus,
  )
where

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
import Amazonka.ServiceCatalogAppRegistry.Types

-- | /See:/ 'newSyncResource' smart constructor.
data SyncResource = SyncResource'
  { -- | The type of resource of which the application will be associated.
    SyncResource -> ResourceType
resourceType :: ResourceType,
    -- | An entity you can work with and specify with a name or ID. Examples
    -- include an Amazon EC2 instance, an Amazon Web Services CloudFormation
    -- stack, or an Amazon S3 bucket.
    SyncResource -> Text
resource :: Prelude.Text
  }
  deriving (SyncResource -> SyncResource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SyncResource -> SyncResource -> Bool
$c/= :: SyncResource -> SyncResource -> Bool
== :: SyncResource -> SyncResource -> Bool
$c== :: SyncResource -> SyncResource -> Bool
Prelude.Eq, ReadPrec [SyncResource]
ReadPrec SyncResource
Int -> ReadS SyncResource
ReadS [SyncResource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SyncResource]
$creadListPrec :: ReadPrec [SyncResource]
readPrec :: ReadPrec SyncResource
$creadPrec :: ReadPrec SyncResource
readList :: ReadS [SyncResource]
$creadList :: ReadS [SyncResource]
readsPrec :: Int -> ReadS SyncResource
$creadsPrec :: Int -> ReadS SyncResource
Prelude.Read, Int -> SyncResource -> ShowS
[SyncResource] -> ShowS
SyncResource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SyncResource] -> ShowS
$cshowList :: [SyncResource] -> ShowS
show :: SyncResource -> String
$cshow :: SyncResource -> String
showsPrec :: Int -> SyncResource -> ShowS
$cshowsPrec :: Int -> SyncResource -> ShowS
Prelude.Show, forall x. Rep SyncResource x -> SyncResource
forall x. SyncResource -> Rep SyncResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SyncResource x -> SyncResource
$cfrom :: forall x. SyncResource -> Rep SyncResource x
Prelude.Generic)

-- |
-- Create a value of 'SyncResource' 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:
--
-- 'resourceType', 'syncResource_resourceType' - The type of resource of which the application will be associated.
--
-- 'resource', 'syncResource_resource' - An entity you can work with and specify with a name or ID. Examples
-- include an Amazon EC2 instance, an Amazon Web Services CloudFormation
-- stack, or an Amazon S3 bucket.
newSyncResource ::
  -- | 'resourceType'
  ResourceType ->
  -- | 'resource'
  Prelude.Text ->
  SyncResource
newSyncResource :: ResourceType -> Text -> SyncResource
newSyncResource ResourceType
pResourceType_ Text
pResource_ =
  SyncResource'
    { $sel:resourceType:SyncResource' :: ResourceType
resourceType = ResourceType
pResourceType_,
      $sel:resource:SyncResource' :: Text
resource = Text
pResource_
    }

-- | The type of resource of which the application will be associated.
syncResource_resourceType :: Lens.Lens' SyncResource ResourceType
syncResource_resourceType :: Lens' SyncResource ResourceType
syncResource_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncResource' {ResourceType
resourceType :: ResourceType
$sel:resourceType:SyncResource' :: SyncResource -> ResourceType
resourceType} -> ResourceType
resourceType) (\s :: SyncResource
s@SyncResource' {} ResourceType
a -> SyncResource
s {$sel:resourceType:SyncResource' :: ResourceType
resourceType = ResourceType
a} :: SyncResource)

-- | An entity you can work with and specify with a name or ID. Examples
-- include an Amazon EC2 instance, an Amazon Web Services CloudFormation
-- stack, or an Amazon S3 bucket.
syncResource_resource :: Lens.Lens' SyncResource Prelude.Text
syncResource_resource :: Lens' SyncResource Text
syncResource_resource = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncResource' {Text
resource :: Text
$sel:resource:SyncResource' :: SyncResource -> Text
resource} -> Text
resource) (\s :: SyncResource
s@SyncResource' {} Text
a -> SyncResource
s {$sel:resource:SyncResource' :: Text
resource = Text
a} :: SyncResource)

instance Core.AWSRequest SyncResource where
  type AWSResponse SyncResource = SyncResourceResponse
  request :: (Service -> Service) -> SyncResource -> Request SyncResource
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 SyncResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SyncResource)))
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 SyncAction
-> Maybe Text -> Maybe Text -> Int -> SyncResourceResponse
SyncResourceResponse'
            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
"actionTaken")
            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
"applicationArn")
            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable SyncResource where
  hashWithSalt :: Int -> SyncResource -> Int
hashWithSalt Int
_salt SyncResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
$sel:resource:SyncResource' :: SyncResource -> Text
$sel:resourceType:SyncResource' :: SyncResource -> ResourceType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ResourceType
resourceType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resource

instance Prelude.NFData SyncResource where
  rnf :: SyncResource -> ()
rnf SyncResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
$sel:resource:SyncResource' :: SyncResource -> Text
$sel:resourceType:SyncResource' :: SyncResource -> ResourceType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ResourceType
resourceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resource

instance Data.ToHeaders SyncResource where
  toHeaders :: SyncResource -> 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.ToJSON SyncResource where
  toJSON :: SyncResource -> Value
toJSON = forall a b. a -> b -> a
Prelude.const (Object -> Value
Data.Object forall a. Monoid a => a
Prelude.mempty)

instance Data.ToPath SyncResource where
  toPath :: SyncResource -> ByteString
toPath SyncResource' {Text
ResourceType
resource :: Text
resourceType :: ResourceType
$sel:resource:SyncResource' :: SyncResource -> Text
$sel:resourceType:SyncResource' :: SyncResource -> ResourceType
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/sync/",
        forall a. ToByteString a => a -> ByteString
Data.toBS ResourceType
resourceType,
        ByteString
"/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
resource
      ]

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

-- | /See:/ 'newSyncResourceResponse' smart constructor.
data SyncResourceResponse = SyncResourceResponse'
  { -- | The results of the output if an application is associated with an ARN
    -- value, which could be @syncStarted@ or None.
    SyncResourceResponse -> Maybe SyncAction
actionTaken :: Prelude.Maybe SyncAction,
    -- | The Amazon resource name (ARN) that specifies the application.
    SyncResourceResponse -> Maybe Text
applicationArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon resource name (ARN) that specifies the resource.
    SyncResourceResponse -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    SyncResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SyncResourceResponse -> SyncResourceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SyncResourceResponse -> SyncResourceResponse -> Bool
$c/= :: SyncResourceResponse -> SyncResourceResponse -> Bool
== :: SyncResourceResponse -> SyncResourceResponse -> Bool
$c== :: SyncResourceResponse -> SyncResourceResponse -> Bool
Prelude.Eq, ReadPrec [SyncResourceResponse]
ReadPrec SyncResourceResponse
Int -> ReadS SyncResourceResponse
ReadS [SyncResourceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SyncResourceResponse]
$creadListPrec :: ReadPrec [SyncResourceResponse]
readPrec :: ReadPrec SyncResourceResponse
$creadPrec :: ReadPrec SyncResourceResponse
readList :: ReadS [SyncResourceResponse]
$creadList :: ReadS [SyncResourceResponse]
readsPrec :: Int -> ReadS SyncResourceResponse
$creadsPrec :: Int -> ReadS SyncResourceResponse
Prelude.Read, Int -> SyncResourceResponse -> ShowS
[SyncResourceResponse] -> ShowS
SyncResourceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SyncResourceResponse] -> ShowS
$cshowList :: [SyncResourceResponse] -> ShowS
show :: SyncResourceResponse -> String
$cshow :: SyncResourceResponse -> String
showsPrec :: Int -> SyncResourceResponse -> ShowS
$cshowsPrec :: Int -> SyncResourceResponse -> ShowS
Prelude.Show, forall x. Rep SyncResourceResponse x -> SyncResourceResponse
forall x. SyncResourceResponse -> Rep SyncResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SyncResourceResponse x -> SyncResourceResponse
$cfrom :: forall x. SyncResourceResponse -> Rep SyncResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'SyncResourceResponse' 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:
--
-- 'actionTaken', 'syncResourceResponse_actionTaken' - The results of the output if an application is associated with an ARN
-- value, which could be @syncStarted@ or None.
--
-- 'applicationArn', 'syncResourceResponse_applicationArn' - The Amazon resource name (ARN) that specifies the application.
--
-- 'resourceArn', 'syncResourceResponse_resourceArn' - The Amazon resource name (ARN) that specifies the resource.
--
-- 'httpStatus', 'syncResourceResponse_httpStatus' - The response's http status code.
newSyncResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SyncResourceResponse
newSyncResourceResponse :: Int -> SyncResourceResponse
newSyncResourceResponse Int
pHttpStatus_ =
  SyncResourceResponse'
    { $sel:actionTaken:SyncResourceResponse' :: Maybe SyncAction
actionTaken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:applicationArn:SyncResourceResponse' :: Maybe Text
applicationArn = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:SyncResourceResponse' :: Maybe Text
resourceArn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SyncResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The results of the output if an application is associated with an ARN
-- value, which could be @syncStarted@ or None.
syncResourceResponse_actionTaken :: Lens.Lens' SyncResourceResponse (Prelude.Maybe SyncAction)
syncResourceResponse_actionTaken :: Lens' SyncResourceResponse (Maybe SyncAction)
syncResourceResponse_actionTaken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncResourceResponse' {Maybe SyncAction
actionTaken :: Maybe SyncAction
$sel:actionTaken:SyncResourceResponse' :: SyncResourceResponse -> Maybe SyncAction
actionTaken} -> Maybe SyncAction
actionTaken) (\s :: SyncResourceResponse
s@SyncResourceResponse' {} Maybe SyncAction
a -> SyncResourceResponse
s {$sel:actionTaken:SyncResourceResponse' :: Maybe SyncAction
actionTaken = Maybe SyncAction
a} :: SyncResourceResponse)

-- | The Amazon resource name (ARN) that specifies the application.
syncResourceResponse_applicationArn :: Lens.Lens' SyncResourceResponse (Prelude.Maybe Prelude.Text)
syncResourceResponse_applicationArn :: Lens' SyncResourceResponse (Maybe Text)
syncResourceResponse_applicationArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncResourceResponse' {Maybe Text
applicationArn :: Maybe Text
$sel:applicationArn:SyncResourceResponse' :: SyncResourceResponse -> Maybe Text
applicationArn} -> Maybe Text
applicationArn) (\s :: SyncResourceResponse
s@SyncResourceResponse' {} Maybe Text
a -> SyncResourceResponse
s {$sel:applicationArn:SyncResourceResponse' :: Maybe Text
applicationArn = Maybe Text
a} :: SyncResourceResponse)

-- | The Amazon resource name (ARN) that specifies the resource.
syncResourceResponse_resourceArn :: Lens.Lens' SyncResourceResponse (Prelude.Maybe Prelude.Text)
syncResourceResponse_resourceArn :: Lens' SyncResourceResponse (Maybe Text)
syncResourceResponse_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyncResourceResponse' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:SyncResourceResponse' :: SyncResourceResponse -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: SyncResourceResponse
s@SyncResourceResponse' {} Maybe Text
a -> SyncResourceResponse
s {$sel:resourceArn:SyncResourceResponse' :: Maybe Text
resourceArn = Maybe Text
a} :: SyncResourceResponse)

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

instance Prelude.NFData SyncResourceResponse where
  rnf :: SyncResourceResponse -> ()
rnf SyncResourceResponse' {Int
Maybe Text
Maybe SyncAction
httpStatus :: Int
resourceArn :: Maybe Text
applicationArn :: Maybe Text
actionTaken :: Maybe SyncAction
$sel:httpStatus:SyncResourceResponse' :: SyncResourceResponse -> Int
$sel:resourceArn:SyncResourceResponse' :: SyncResourceResponse -> Maybe Text
$sel:applicationArn:SyncResourceResponse' :: SyncResourceResponse -> Maybe Text
$sel:actionTaken:SyncResourceResponse' :: SyncResourceResponse -> Maybe SyncAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SyncAction
actionTaken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
applicationArn
      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 Int
httpStatus