{-# 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.Grafana.AssociateLicense
-- 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)
--
-- Assigns a Grafana Enterprise license to a workspace. Upgrading to
-- Grafana Enterprise incurs additional fees. For more information, see
-- <https://docs.aws.amazon.com/grafana/latest/userguide/upgrade-to-Grafana-Enterprise.html Upgrade a workspace to Grafana Enterprise>.
module Amazonka.Grafana.AssociateLicense
  ( -- * Creating a Request
    AssociateLicense (..),
    newAssociateLicense,

    -- * Request Lenses
    associateLicense_licenseType,
    associateLicense_workspaceId,

    -- * Destructuring the Response
    AssociateLicenseResponse (..),
    newAssociateLicenseResponse,

    -- * Response Lenses
    associateLicenseResponse_httpStatus,
    associateLicenseResponse_workspace,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Grafana.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateLicense' smart constructor.
data AssociateLicense = AssociateLicense'
  { -- | The type of license to associate with the workspace.
    AssociateLicense -> LicenseType
licenseType :: LicenseType,
    -- | The ID of the workspace to associate the license with.
    AssociateLicense -> Text
workspaceId :: Prelude.Text
  }
  deriving (AssociateLicense -> AssociateLicense -> Bool
(AssociateLicense -> AssociateLicense -> Bool)
-> (AssociateLicense -> AssociateLicense -> Bool)
-> Eq AssociateLicense
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateLicense -> AssociateLicense -> Bool
$c/= :: AssociateLicense -> AssociateLicense -> Bool
== :: AssociateLicense -> AssociateLicense -> Bool
$c== :: AssociateLicense -> AssociateLicense -> Bool
Prelude.Eq, ReadPrec [AssociateLicense]
ReadPrec AssociateLicense
Int -> ReadS AssociateLicense
ReadS [AssociateLicense]
(Int -> ReadS AssociateLicense)
-> ReadS [AssociateLicense]
-> ReadPrec AssociateLicense
-> ReadPrec [AssociateLicense]
-> Read AssociateLicense
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateLicense]
$creadListPrec :: ReadPrec [AssociateLicense]
readPrec :: ReadPrec AssociateLicense
$creadPrec :: ReadPrec AssociateLicense
readList :: ReadS [AssociateLicense]
$creadList :: ReadS [AssociateLicense]
readsPrec :: Int -> ReadS AssociateLicense
$creadsPrec :: Int -> ReadS AssociateLicense
Prelude.Read, Int -> AssociateLicense -> ShowS
[AssociateLicense] -> ShowS
AssociateLicense -> String
(Int -> AssociateLicense -> ShowS)
-> (AssociateLicense -> String)
-> ([AssociateLicense] -> ShowS)
-> Show AssociateLicense
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateLicense] -> ShowS
$cshowList :: [AssociateLicense] -> ShowS
show :: AssociateLicense -> String
$cshow :: AssociateLicense -> String
showsPrec :: Int -> AssociateLicense -> ShowS
$cshowsPrec :: Int -> AssociateLicense -> ShowS
Prelude.Show, (forall x. AssociateLicense -> Rep AssociateLicense x)
-> (forall x. Rep AssociateLicense x -> AssociateLicense)
-> Generic AssociateLicense
forall x. Rep AssociateLicense x -> AssociateLicense
forall x. AssociateLicense -> Rep AssociateLicense x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssociateLicense x -> AssociateLicense
$cfrom :: forall x. AssociateLicense -> Rep AssociateLicense x
Prelude.Generic)

-- |
-- Create a value of 'AssociateLicense' 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:
--
-- 'licenseType', 'associateLicense_licenseType' - The type of license to associate with the workspace.
--
-- 'workspaceId', 'associateLicense_workspaceId' - The ID of the workspace to associate the license with.
newAssociateLicense ::
  -- | 'licenseType'
  LicenseType ->
  -- | 'workspaceId'
  Prelude.Text ->
  AssociateLicense
newAssociateLicense :: LicenseType -> Text -> AssociateLicense
newAssociateLicense LicenseType
pLicenseType_ Text
pWorkspaceId_ =
  AssociateLicense' :: LicenseType -> Text -> AssociateLicense
AssociateLicense'
    { $sel:licenseType:AssociateLicense' :: LicenseType
licenseType = LicenseType
pLicenseType_,
      $sel:workspaceId:AssociateLicense' :: Text
workspaceId = Text
pWorkspaceId_
    }

-- | The type of license to associate with the workspace.
associateLicense_licenseType :: Lens.Lens' AssociateLicense LicenseType
associateLicense_licenseType :: (LicenseType -> f LicenseType)
-> AssociateLicense -> f AssociateLicense
associateLicense_licenseType = (AssociateLicense -> LicenseType)
-> (AssociateLicense -> LicenseType -> AssociateLicense)
-> Lens AssociateLicense AssociateLicense LicenseType LicenseType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLicense' {LicenseType
licenseType :: LicenseType
$sel:licenseType:AssociateLicense' :: AssociateLicense -> LicenseType
licenseType} -> LicenseType
licenseType) (\s :: AssociateLicense
s@AssociateLicense' {} LicenseType
a -> AssociateLicense
s {$sel:licenseType:AssociateLicense' :: LicenseType
licenseType = LicenseType
a} :: AssociateLicense)

-- | The ID of the workspace to associate the license with.
associateLicense_workspaceId :: Lens.Lens' AssociateLicense Prelude.Text
associateLicense_workspaceId :: (Text -> f Text) -> AssociateLicense -> f AssociateLicense
associateLicense_workspaceId = (AssociateLicense -> Text)
-> (AssociateLicense -> Text -> AssociateLicense)
-> Lens AssociateLicense AssociateLicense Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLicense' {Text
workspaceId :: Text
$sel:workspaceId:AssociateLicense' :: AssociateLicense -> Text
workspaceId} -> Text
workspaceId) (\s :: AssociateLicense
s@AssociateLicense' {} Text
a -> AssociateLicense
s {$sel:workspaceId:AssociateLicense' :: Text
workspaceId = Text
a} :: AssociateLicense)

instance Core.AWSRequest AssociateLicense where
  type
    AWSResponse AssociateLicense =
      AssociateLicenseResponse
  request :: AssociateLicense -> Request AssociateLicense
request = Service -> AssociateLicense -> Request AssociateLicense
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AssociateLicense
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateLicense)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AssociateLicense))
-> Logger
-> Service
-> Proxy AssociateLicense
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AssociateLicense)))
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 ->
          Int -> WorkspaceDescription -> AssociateLicenseResponse
AssociateLicenseResponse'
            (Int -> WorkspaceDescription -> AssociateLicenseResponse)
-> Either String Int
-> Either String (WorkspaceDescription -> AssociateLicenseResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (WorkspaceDescription -> AssociateLicenseResponse)
-> Either String WorkspaceDescription
-> Either String AssociateLicenseResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String WorkspaceDescription
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"workspace")
      )

instance Prelude.Hashable AssociateLicense

instance Prelude.NFData AssociateLicense

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

instance Core.ToPath AssociateLicense where
  toPath :: AssociateLicense -> ByteString
toPath AssociateLicense' {Text
LicenseType
workspaceId :: Text
licenseType :: LicenseType
$sel:workspaceId:AssociateLicense' :: AssociateLicense -> Text
$sel:licenseType:AssociateLicense' :: AssociateLicense -> LicenseType
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/workspaces/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
workspaceId,
        ByteString
"/licenses/",
        LicenseType -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS LicenseType
licenseType
      ]

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

-- | /See:/ 'newAssociateLicenseResponse' smart constructor.
data AssociateLicenseResponse = AssociateLicenseResponse'
  { -- | The response's http status code.
    AssociateLicenseResponse -> Int
httpStatus :: Prelude.Int,
    -- | A structure containing data about the workspace.
    AssociateLicenseResponse -> WorkspaceDescription
workspace :: WorkspaceDescription
  }
  deriving (AssociateLicenseResponse -> AssociateLicenseResponse -> Bool
(AssociateLicenseResponse -> AssociateLicenseResponse -> Bool)
-> (AssociateLicenseResponse -> AssociateLicenseResponse -> Bool)
-> Eq AssociateLicenseResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateLicenseResponse -> AssociateLicenseResponse -> Bool
$c/= :: AssociateLicenseResponse -> AssociateLicenseResponse -> Bool
== :: AssociateLicenseResponse -> AssociateLicenseResponse -> Bool
$c== :: AssociateLicenseResponse -> AssociateLicenseResponse -> Bool
Prelude.Eq, Int -> AssociateLicenseResponse -> ShowS
[AssociateLicenseResponse] -> ShowS
AssociateLicenseResponse -> String
(Int -> AssociateLicenseResponse -> ShowS)
-> (AssociateLicenseResponse -> String)
-> ([AssociateLicenseResponse] -> ShowS)
-> Show AssociateLicenseResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateLicenseResponse] -> ShowS
$cshowList :: [AssociateLicenseResponse] -> ShowS
show :: AssociateLicenseResponse -> String
$cshow :: AssociateLicenseResponse -> String
showsPrec :: Int -> AssociateLicenseResponse -> ShowS
$cshowsPrec :: Int -> AssociateLicenseResponse -> ShowS
Prelude.Show, (forall x.
 AssociateLicenseResponse -> Rep AssociateLicenseResponse x)
-> (forall x.
    Rep AssociateLicenseResponse x -> AssociateLicenseResponse)
-> Generic AssociateLicenseResponse
forall x.
Rep AssociateLicenseResponse x -> AssociateLicenseResponse
forall x.
AssociateLicenseResponse -> Rep AssociateLicenseResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateLicenseResponse x -> AssociateLicenseResponse
$cfrom :: forall x.
AssociateLicenseResponse -> Rep AssociateLicenseResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateLicenseResponse' 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:
--
-- 'httpStatus', 'associateLicenseResponse_httpStatus' - The response's http status code.
--
-- 'workspace', 'associateLicenseResponse_workspace' - A structure containing data about the workspace.
newAssociateLicenseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'workspace'
  WorkspaceDescription ->
  AssociateLicenseResponse
newAssociateLicenseResponse :: Int -> WorkspaceDescription -> AssociateLicenseResponse
newAssociateLicenseResponse Int
pHttpStatus_ WorkspaceDescription
pWorkspace_ =
  AssociateLicenseResponse' :: Int -> WorkspaceDescription -> AssociateLicenseResponse
AssociateLicenseResponse'
    { $sel:httpStatus:AssociateLicenseResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:workspace:AssociateLicenseResponse' :: WorkspaceDescription
workspace = WorkspaceDescription
pWorkspace_
    }

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

-- | A structure containing data about the workspace.
associateLicenseResponse_workspace :: Lens.Lens' AssociateLicenseResponse WorkspaceDescription
associateLicenseResponse_workspace :: (WorkspaceDescription -> f WorkspaceDescription)
-> AssociateLicenseResponse -> f AssociateLicenseResponse
associateLicenseResponse_workspace = (AssociateLicenseResponse -> WorkspaceDescription)
-> (AssociateLicenseResponse
    -> WorkspaceDescription -> AssociateLicenseResponse)
-> Lens
     AssociateLicenseResponse
     AssociateLicenseResponse
     WorkspaceDescription
     WorkspaceDescription
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateLicenseResponse' {WorkspaceDescription
workspace :: WorkspaceDescription
$sel:workspace:AssociateLicenseResponse' :: AssociateLicenseResponse -> WorkspaceDescription
workspace} -> WorkspaceDescription
workspace) (\s :: AssociateLicenseResponse
s@AssociateLicenseResponse' {} WorkspaceDescription
a -> AssociateLicenseResponse
s {$sel:workspace:AssociateLicenseResponse' :: WorkspaceDescription
workspace = WorkspaceDescription
a} :: AssociateLicenseResponse)

instance Prelude.NFData AssociateLicenseResponse