{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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_applicationArn,
    syncResourceResponse_actionTaken,
    syncResourceResponse_resourceArn,
    syncResourceResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(SyncResource -> SyncResource -> Bool)
-> (SyncResource -> SyncResource -> Bool) -> Eq SyncResource
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]
(Int -> ReadS SyncResource)
-> ReadS [SyncResource]
-> ReadPrec SyncResource
-> ReadPrec [SyncResource]
-> Read 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
(Int -> SyncResource -> ShowS)
-> (SyncResource -> String)
-> ([SyncResource] -> ShowS)
-> Show SyncResource
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. SyncResource -> Rep SyncResource x)
-> (forall x. Rep SyncResource x -> SyncResource)
-> Generic SyncResource
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' :: ResourceType -> Text -> SyncResource
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 :: (ResourceType -> f ResourceType) -> SyncResource -> f SyncResource
syncResource_resourceType = (SyncResource -> ResourceType)
-> (SyncResource -> ResourceType -> SyncResource)
-> Lens SyncResource SyncResource ResourceType 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 :: (Text -> f Text) -> SyncResource -> f SyncResource
syncResource_resource = (SyncResource -> Text)
-> (SyncResource -> Text -> SyncResource)
-> Lens SyncResource SyncResource Text Text
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 :: SyncResource -> Request SyncResource
request = Service -> SyncResource -> Request SyncResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SyncResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SyncResource)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse SyncResource))
-> Logger
-> Service
-> Proxy SyncResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SyncResource)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe SyncAction -> Maybe Text -> Int -> SyncResourceResponse
SyncResourceResponse'
            (Maybe Text
 -> Maybe SyncAction -> Maybe Text -> Int -> SyncResourceResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe SyncAction -> Maybe Text -> Int -> SyncResourceResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"applicationArn")
            Either
  String
  (Maybe SyncAction -> Maybe Text -> Int -> SyncResourceResponse)
-> Either String (Maybe SyncAction)
-> Either String (Maybe Text -> Int -> SyncResourceResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe SyncAction)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"actionTaken")
            Either String (Maybe Text -> Int -> SyncResourceResponse)
-> Either String (Maybe Text)
-> Either String (Int -> SyncResourceResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"resourceArn")
            Either String (Int -> SyncResourceResponse)
-> Either String Int -> Either String SyncResourceResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable SyncResource

instance Prelude.NFData SyncResource

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

instance Core.ToJSON SyncResource where
  toJSON :: SyncResource -> Value
toJSON = Value -> SyncResource -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newSyncResourceResponse' smart constructor.
data SyncResourceResponse = SyncResourceResponse'
  { -- | The Amazon resource name (ARN) that specifies the application.
    SyncResourceResponse -> Maybe Text
applicationArn :: Prelude.Maybe Prelude.Text,
    -- | 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 resource.
    SyncResourceResponse -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    SyncResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SyncResourceResponse -> SyncResourceResponse -> Bool
(SyncResourceResponse -> SyncResourceResponse -> Bool)
-> (SyncResourceResponse -> SyncResourceResponse -> Bool)
-> Eq SyncResourceResponse
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]
(Int -> ReadS SyncResourceResponse)
-> ReadS [SyncResourceResponse]
-> ReadPrec SyncResourceResponse
-> ReadPrec [SyncResourceResponse]
-> Read 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
(Int -> SyncResourceResponse -> ShowS)
-> (SyncResourceResponse -> String)
-> ([SyncResourceResponse] -> ShowS)
-> Show SyncResourceResponse
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. SyncResourceResponse -> Rep SyncResourceResponse x)
-> (forall x. Rep SyncResourceResponse x -> SyncResourceResponse)
-> Generic SyncResourceResponse
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:
--
-- 'applicationArn', 'syncResourceResponse_applicationArn' - The Amazon resource name (ARN) that specifies the application.
--
-- 'actionTaken', 'syncResourceResponse_actionTaken' - The results of the output if an application is associated with an ARN
-- value, which could be @syncStarted@ or None.
--
-- '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' :: Maybe Text
-> Maybe SyncAction -> Maybe Text -> Int -> SyncResourceResponse
SyncResourceResponse'
    { $sel:applicationArn:SyncResourceResponse' :: Maybe Text
applicationArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:actionTaken:SyncResourceResponse' :: Maybe SyncAction
actionTaken = Maybe SyncAction
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:SyncResourceResponse' :: Maybe Text
resourceArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SyncResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon resource name (ARN) that specifies the application.
syncResourceResponse_applicationArn :: Lens.Lens' SyncResourceResponse (Prelude.Maybe Prelude.Text)
syncResourceResponse_applicationArn :: (Maybe Text -> f (Maybe Text))
-> SyncResourceResponse -> f SyncResourceResponse
syncResourceResponse_applicationArn = (SyncResourceResponse -> Maybe Text)
-> (SyncResourceResponse -> Maybe Text -> SyncResourceResponse)
-> Lens
     SyncResourceResponse SyncResourceResponse (Maybe Text) (Maybe Text)
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 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 :: (Maybe SyncAction -> f (Maybe SyncAction))
-> SyncResourceResponse -> f SyncResourceResponse
syncResourceResponse_actionTaken = (SyncResourceResponse -> Maybe SyncAction)
-> (SyncResourceResponse
    -> Maybe SyncAction -> SyncResourceResponse)
-> Lens
     SyncResourceResponse
     SyncResourceResponse
     (Maybe SyncAction)
     (Maybe SyncAction)
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 resource.
syncResourceResponse_resourceArn :: Lens.Lens' SyncResourceResponse (Prelude.Maybe Prelude.Text)
syncResourceResponse_resourceArn :: (Maybe Text -> f (Maybe Text))
-> SyncResourceResponse -> f SyncResourceResponse
syncResourceResponse_resourceArn = (SyncResourceResponse -> Maybe Text)
-> (SyncResourceResponse -> Maybe Text -> SyncResourceResponse)
-> Lens
     SyncResourceResponse SyncResourceResponse (Maybe Text) (Maybe Text)
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 :: (Int -> f Int) -> SyncResourceResponse -> f SyncResourceResponse
syncResourceResponse_httpStatus = (SyncResourceResponse -> Int)
-> (SyncResourceResponse -> Int -> SyncResourceResponse)
-> Lens SyncResourceResponse SyncResourceResponse Int Int
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