{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new 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.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.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
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]
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
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. 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'
    { $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 :: Lens' CreateResource Text
createResource_organizationId = 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 :: Lens' CreateResource Text
createResource_name = 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 :: Lens' CreateResource ResourceType
createResource_type = 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 :: (Service -> Service) -> CreateResource -> Request CreateResource
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 CreateResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateResource)))
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 Text -> Int -> CreateResourceResponse
CreateResourceResponse'
            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
"ResourceId")
            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 CreateResource where
  hashWithSalt :: Int -> CreateResource -> Int
hashWithSalt Int
_salt CreateResource' {Text
ResourceType
type' :: ResourceType
name :: Text
organizationId :: Text
$sel:type':CreateResource' :: CreateResource -> ResourceType
$sel:name:CreateResource' :: CreateResource -> Text
$sel:organizationId:CreateResource' :: CreateResource -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
organizationId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ResourceType
type'

instance Prelude.NFData CreateResource where
  rnf :: CreateResource -> ()
rnf CreateResource' {Text
ResourceType
type' :: ResourceType
name :: Text
organizationId :: Text
$sel:type':CreateResource' :: CreateResource -> ResourceType
$sel:name:CreateResource' :: CreateResource -> Text
$sel:organizationId:CreateResource' :: CreateResource -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
organizationId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ResourceType
type'

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"OrganizationId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
organizationId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ResourceType
type')
          ]
      )

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

instance Data.ToQuery CreateResource where
  toQuery :: CreateResource -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:resourceId:CreateResourceResponse' :: Maybe Text
resourceId =
        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 :: Lens' CreateResourceResponse (Maybe Text)
createResourceResponse_resourceId = 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 :: Lens' CreateResourceResponse Int
createResourceResponse_httpStatus = 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 where
  rnf :: CreateResourceResponse -> ()
rnf CreateResourceResponse' {Int
Maybe Text
httpStatus :: Int
resourceId :: Maybe Text
$sel:httpStatus:CreateResourceResponse' :: CreateResourceResponse -> Int
$sel:resourceId:CreateResourceResponse' :: CreateResourceResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus