{-# 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.WorkMail.CreateResource
-- 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)
--
-- Creates a new Amazon WorkMail resource.
module Amazonka.WorkMail.CreateResource
  ( -- * Creating a Request
    CreateResource (..),
    newCreateResource,

    -- * Request Lenses
    createResource_organizationId,
    createResource_name,
    createResource_type,

    -- * Destructuring the Response
    CreateResourceResponse (..),
    newCreateResourceResponse,

    -- * Response Lenses
    createResourceResponse_resourceId,
    createResourceResponse_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.WorkMail.Types

-- | /See:/ 'newCreateResource' smart constructor.
data CreateResource = CreateResource'
  { -- | The identifier associated with the organization for which the resource
    -- is created.
    CreateResource -> Text
organizationId :: Prelude.Text,
    -- | The name of the new resource.
    CreateResource -> Text
name :: Prelude.Text,
    -- | The type of the new resource. The available types are @equipment@ and
    -- @room@.
    CreateResource -> ResourceType
type' :: ResourceType
  }
  deriving (CreateResource -> CreateResource -> Bool
(CreateResource -> CreateResource -> Bool)
-> (CreateResource -> CreateResource -> Bool) -> Eq CreateResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResource -> CreateResource -> Bool
$c/= :: CreateResource -> CreateResource -> Bool
== :: CreateResource -> CreateResource -> Bool
$c== :: CreateResource -> CreateResource -> Bool
Prelude.Eq, ReadPrec [CreateResource]
ReadPrec CreateResource
Int -> ReadS CreateResource
ReadS [CreateResource]
(Int -> ReadS CreateResource)
-> ReadS [CreateResource]
-> ReadPrec CreateResource
-> ReadPrec [CreateResource]
-> Read CreateResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResource]
$creadListPrec :: ReadPrec [CreateResource]
readPrec :: ReadPrec CreateResource
$creadPrec :: ReadPrec CreateResource
readList :: ReadS [CreateResource]
$creadList :: ReadS [CreateResource]
readsPrec :: Int -> ReadS CreateResource
$creadsPrec :: Int -> ReadS CreateResource
Prelude.Read, Int -> CreateResource -> ShowS
[CreateResource] -> ShowS
CreateResource -> String
(Int -> CreateResource -> ShowS)
-> (CreateResource -> String)
-> ([CreateResource] -> ShowS)
-> Show CreateResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResource] -> ShowS
$cshowList :: [CreateResource] -> ShowS
show :: CreateResource -> String
$cshow :: CreateResource -> String
showsPrec :: Int -> CreateResource -> ShowS
$cshowsPrec :: Int -> CreateResource -> ShowS
Prelude.Show, (forall x. CreateResource -> Rep CreateResource x)
-> (forall x. Rep CreateResource x -> CreateResource)
-> Generic CreateResource
forall x. Rep CreateResource x -> CreateResource
forall x. CreateResource -> Rep CreateResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateResource x -> CreateResource
$cfrom :: forall x. CreateResource -> Rep CreateResource x
Prelude.Generic)

-- |
-- Create a value of 'CreateResource' 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:
--
-- 'organizationId', 'createResource_organizationId' - The identifier associated with the organization for which the resource
-- is created.
--
-- 'name', 'createResource_name' - The name of the new resource.
--
-- 'type'', 'createResource_type' - The type of the new resource. The available types are @equipment@ and
-- @room@.
newCreateResource ::
  -- | 'organizationId'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'type''
  ResourceType ->
  CreateResource
newCreateResource :: Text -> Text -> ResourceType -> CreateResource
newCreateResource Text
pOrganizationId_ Text
pName_ ResourceType
pType_ =
  CreateResource' :: Text -> Text -> ResourceType -> CreateResource
CreateResource'
    { $sel:organizationId:CreateResource' :: Text
organizationId = Text
pOrganizationId_,
      $sel:name:CreateResource' :: Text
name = Text
pName_,
      $sel:type':CreateResource' :: ResourceType
type' = ResourceType
pType_
    }

-- | The identifier associated with the organization for which the resource
-- is created.
createResource_organizationId :: Lens.Lens' CreateResource Prelude.Text
createResource_organizationId :: (Text -> f Text) -> CreateResource -> f CreateResource
createResource_organizationId = (CreateResource -> Text)
-> (CreateResource -> Text -> CreateResource)
-> Lens CreateResource CreateResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResource' {Text
organizationId :: Text
$sel:organizationId:CreateResource' :: CreateResource -> Text
organizationId} -> Text
organizationId) (\s :: CreateResource
s@CreateResource' {} Text
a -> CreateResource
s {$sel:organizationId:CreateResource' :: Text
organizationId = Text
a} :: CreateResource)

-- | The name of the new resource.
createResource_name :: Lens.Lens' CreateResource Prelude.Text
createResource_name :: (Text -> f Text) -> CreateResource -> f CreateResource
createResource_name = (CreateResource -> Text)
-> (CreateResource -> Text -> CreateResource)
-> Lens CreateResource CreateResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResource' {Text
name :: Text
$sel:name:CreateResource' :: CreateResource -> Text
name} -> Text
name) (\s :: CreateResource
s@CreateResource' {} Text
a -> CreateResource
s {$sel:name:CreateResource' :: Text
name = Text
a} :: CreateResource)

-- | The type of the new resource. The available types are @equipment@ and
-- @room@.
createResource_type :: Lens.Lens' CreateResource ResourceType
createResource_type :: (ResourceType -> f ResourceType)
-> CreateResource -> f CreateResource
createResource_type = (CreateResource -> ResourceType)
-> (CreateResource -> ResourceType -> CreateResource)
-> Lens CreateResource CreateResource ResourceType ResourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResource' {ResourceType
type' :: ResourceType
$sel:type':CreateResource' :: CreateResource -> ResourceType
type'} -> ResourceType
type') (\s :: CreateResource
s@CreateResource' {} ResourceType
a -> CreateResource
s {$sel:type':CreateResource' :: ResourceType
type' = ResourceType
a} :: CreateResource)

instance Core.AWSRequest CreateResource where
  type
    AWSResponse CreateResource =
      CreateResourceResponse
  request :: CreateResource -> Request CreateResource
request = Service -> CreateResource -> Request CreateResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateResource)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateResource))
-> Logger
-> Service
-> Proxy CreateResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateResource)))
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 -> Int -> CreateResourceResponse
CreateResourceResponse'
            (Maybe Text -> Int -> CreateResourceResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateResourceResponse)
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
"ResourceId")
            Either String (Int -> CreateResourceResponse)
-> Either String Int -> Either String CreateResourceResponse
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 CreateResource

instance Prelude.NFData CreateResource

instance Core.ToHeaders CreateResource where
  toHeaders :: CreateResource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateResource -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"WorkMailService.CreateResource" ::
                          Prelude.ByteString
                      ),
            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 CreateResource where
  toJSON :: CreateResource -> Value
toJSON CreateResource' {Text
ResourceType
type' :: ResourceType
name :: Text
organizationId :: Text
$sel:type':CreateResource' :: CreateResource -> ResourceType
$sel:name:CreateResource' :: CreateResource -> Text
$sel:organizationId:CreateResource' :: CreateResource -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"OrganizationId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
organizationId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> ResourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceType
type')
          ]
      )

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

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

-- | /See:/ 'newCreateResourceResponse' smart constructor.
data CreateResourceResponse = CreateResourceResponse'
  { -- | The identifier of the new resource.
    CreateResourceResponse -> Maybe Text
resourceId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateResourceResponse -> CreateResourceResponse -> Bool
(CreateResourceResponse -> CreateResourceResponse -> Bool)
-> (CreateResourceResponse -> CreateResourceResponse -> Bool)
-> Eq CreateResourceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResourceResponse -> CreateResourceResponse -> Bool
$c/= :: CreateResourceResponse -> CreateResourceResponse -> Bool
== :: CreateResourceResponse -> CreateResourceResponse -> Bool
$c== :: CreateResourceResponse -> CreateResourceResponse -> Bool
Prelude.Eq, ReadPrec [CreateResourceResponse]
ReadPrec CreateResourceResponse
Int -> ReadS CreateResourceResponse
ReadS [CreateResourceResponse]
(Int -> ReadS CreateResourceResponse)
-> ReadS [CreateResourceResponse]
-> ReadPrec CreateResourceResponse
-> ReadPrec [CreateResourceResponse]
-> Read CreateResourceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResourceResponse]
$creadListPrec :: ReadPrec [CreateResourceResponse]
readPrec :: ReadPrec CreateResourceResponse
$creadPrec :: ReadPrec CreateResourceResponse
readList :: ReadS [CreateResourceResponse]
$creadList :: ReadS [CreateResourceResponse]
readsPrec :: Int -> ReadS CreateResourceResponse
$creadsPrec :: Int -> ReadS CreateResourceResponse
Prelude.Read, Int -> CreateResourceResponse -> ShowS
[CreateResourceResponse] -> ShowS
CreateResourceResponse -> String
(Int -> CreateResourceResponse -> ShowS)
-> (CreateResourceResponse -> String)
-> ([CreateResourceResponse] -> ShowS)
-> Show CreateResourceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResourceResponse] -> ShowS
$cshowList :: [CreateResourceResponse] -> ShowS
show :: CreateResourceResponse -> String
$cshow :: CreateResourceResponse -> String
showsPrec :: Int -> CreateResourceResponse -> ShowS
$cshowsPrec :: Int -> CreateResourceResponse -> ShowS
Prelude.Show, (forall x. CreateResourceResponse -> Rep CreateResourceResponse x)
-> (forall x.
    Rep CreateResourceResponse x -> CreateResourceResponse)
-> Generic CreateResourceResponse
forall x. Rep CreateResourceResponse x -> CreateResourceResponse
forall x. CreateResourceResponse -> Rep CreateResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateResourceResponse x -> CreateResourceResponse
$cfrom :: forall x. CreateResourceResponse -> Rep CreateResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateResourceResponse' 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:
--
-- 'resourceId', 'createResourceResponse_resourceId' - The identifier of the new resource.
--
-- 'httpStatus', 'createResourceResponse_httpStatus' - The response's http status code.
newCreateResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateResourceResponse
newCreateResourceResponse :: Int -> CreateResourceResponse
newCreateResourceResponse Int
pHttpStatus_ =
  CreateResourceResponse' :: Maybe Text -> Int -> CreateResourceResponse
CreateResourceResponse'
    { $sel:resourceId:CreateResourceResponse' :: Maybe Text
resourceId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateResourceResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier of the new resource.
createResourceResponse_resourceId :: Lens.Lens' CreateResourceResponse (Prelude.Maybe Prelude.Text)
createResourceResponse_resourceId :: (Maybe Text -> f (Maybe Text))
-> CreateResourceResponse -> f CreateResourceResponse
createResourceResponse_resourceId = (CreateResourceResponse -> Maybe Text)
-> (CreateResourceResponse -> Maybe Text -> CreateResourceResponse)
-> Lens
     CreateResourceResponse
     CreateResourceResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourceResponse' {Maybe Text
resourceId :: Maybe Text
$sel:resourceId:CreateResourceResponse' :: CreateResourceResponse -> Maybe Text
resourceId} -> Maybe Text
resourceId) (\s :: CreateResourceResponse
s@CreateResourceResponse' {} Maybe Text
a -> CreateResourceResponse
s {$sel:resourceId:CreateResourceResponse' :: Maybe Text
resourceId = Maybe Text
a} :: CreateResourceResponse)

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

instance Prelude.NFData CreateResourceResponse