{-# 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.OpenSearch.CreatePackage
-- 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)
--
-- Create a package for use with Amazon OpenSearch Service domains.
module Amazonka.OpenSearch.CreatePackage
  ( -- * Creating a Request
    CreatePackage (..),
    newCreatePackage,

    -- * Request Lenses
    createPackage_packageDescription,
    createPackage_packageName,
    createPackage_packageType,
    createPackage_packageSource,

    -- * Destructuring the Response
    CreatePackageResponse (..),
    newCreatePackageResponse,

    -- * Response Lenses
    createPackageResponse_packageDetails,
    createPackageResponse_httpStatus,
  )
where

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

-- | Container for request parameters to the @ CreatePackage @ operation.
--
-- /See:/ 'newCreatePackage' smart constructor.
data CreatePackage = CreatePackage'
  { -- | Description of the package.
    CreatePackage -> Maybe Text
packageDescription :: Prelude.Maybe Prelude.Text,
    -- | Unique identifier for the package.
    CreatePackage -> Text
packageName :: Prelude.Text,
    -- | Type of package. Currently supports only TXT-DICTIONARY.
    CreatePackage -> PackageType
packageType :: PackageType,
    -- | The Amazon S3 location from which to import the package.
    CreatePackage -> PackageSource
packageSource :: PackageSource
  }
  deriving (CreatePackage -> CreatePackage -> Bool
(CreatePackage -> CreatePackage -> Bool)
-> (CreatePackage -> CreatePackage -> Bool) -> Eq CreatePackage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePackage -> CreatePackage -> Bool
$c/= :: CreatePackage -> CreatePackage -> Bool
== :: CreatePackage -> CreatePackage -> Bool
$c== :: CreatePackage -> CreatePackage -> Bool
Prelude.Eq, ReadPrec [CreatePackage]
ReadPrec CreatePackage
Int -> ReadS CreatePackage
ReadS [CreatePackage]
(Int -> ReadS CreatePackage)
-> ReadS [CreatePackage]
-> ReadPrec CreatePackage
-> ReadPrec [CreatePackage]
-> Read CreatePackage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePackage]
$creadListPrec :: ReadPrec [CreatePackage]
readPrec :: ReadPrec CreatePackage
$creadPrec :: ReadPrec CreatePackage
readList :: ReadS [CreatePackage]
$creadList :: ReadS [CreatePackage]
readsPrec :: Int -> ReadS CreatePackage
$creadsPrec :: Int -> ReadS CreatePackage
Prelude.Read, Int -> CreatePackage -> ShowS
[CreatePackage] -> ShowS
CreatePackage -> String
(Int -> CreatePackage -> ShowS)
-> (CreatePackage -> String)
-> ([CreatePackage] -> ShowS)
-> Show CreatePackage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePackage] -> ShowS
$cshowList :: [CreatePackage] -> ShowS
show :: CreatePackage -> String
$cshow :: CreatePackage -> String
showsPrec :: Int -> CreatePackage -> ShowS
$cshowsPrec :: Int -> CreatePackage -> ShowS
Prelude.Show, (forall x. CreatePackage -> Rep CreatePackage x)
-> (forall x. Rep CreatePackage x -> CreatePackage)
-> Generic CreatePackage
forall x. Rep CreatePackage x -> CreatePackage
forall x. CreatePackage -> Rep CreatePackage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePackage x -> CreatePackage
$cfrom :: forall x. CreatePackage -> Rep CreatePackage x
Prelude.Generic)

-- |
-- Create a value of 'CreatePackage' 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:
--
-- 'packageDescription', 'createPackage_packageDescription' - Description of the package.
--
-- 'packageName', 'createPackage_packageName' - Unique identifier for the package.
--
-- 'packageType', 'createPackage_packageType' - Type of package. Currently supports only TXT-DICTIONARY.
--
-- 'packageSource', 'createPackage_packageSource' - The Amazon S3 location from which to import the package.
newCreatePackage ::
  -- | 'packageName'
  Prelude.Text ->
  -- | 'packageType'
  PackageType ->
  -- | 'packageSource'
  PackageSource ->
  CreatePackage
newCreatePackage :: Text -> PackageType -> PackageSource -> CreatePackage
newCreatePackage
  Text
pPackageName_
  PackageType
pPackageType_
  PackageSource
pPackageSource_ =
    CreatePackage' :: Maybe Text -> Text -> PackageType -> PackageSource -> CreatePackage
CreatePackage'
      { $sel:packageDescription:CreatePackage' :: Maybe Text
packageDescription =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:packageName:CreatePackage' :: Text
packageName = Text
pPackageName_,
        $sel:packageType:CreatePackage' :: PackageType
packageType = PackageType
pPackageType_,
        $sel:packageSource:CreatePackage' :: PackageSource
packageSource = PackageSource
pPackageSource_
      }

-- | Description of the package.
createPackage_packageDescription :: Lens.Lens' CreatePackage (Prelude.Maybe Prelude.Text)
createPackage_packageDescription :: (Maybe Text -> f (Maybe Text)) -> CreatePackage -> f CreatePackage
createPackage_packageDescription = (CreatePackage -> Maybe Text)
-> (CreatePackage -> Maybe Text -> CreatePackage)
-> Lens CreatePackage CreatePackage (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackage' {Maybe Text
packageDescription :: Maybe Text
$sel:packageDescription:CreatePackage' :: CreatePackage -> Maybe Text
packageDescription} -> Maybe Text
packageDescription) (\s :: CreatePackage
s@CreatePackage' {} Maybe Text
a -> CreatePackage
s {$sel:packageDescription:CreatePackage' :: Maybe Text
packageDescription = Maybe Text
a} :: CreatePackage)

-- | Unique identifier for the package.
createPackage_packageName :: Lens.Lens' CreatePackage Prelude.Text
createPackage_packageName :: (Text -> f Text) -> CreatePackage -> f CreatePackage
createPackage_packageName = (CreatePackage -> Text)
-> (CreatePackage -> Text -> CreatePackage)
-> Lens CreatePackage CreatePackage Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackage' {Text
packageName :: Text
$sel:packageName:CreatePackage' :: CreatePackage -> Text
packageName} -> Text
packageName) (\s :: CreatePackage
s@CreatePackage' {} Text
a -> CreatePackage
s {$sel:packageName:CreatePackage' :: Text
packageName = Text
a} :: CreatePackage)

-- | Type of package. Currently supports only TXT-DICTIONARY.
createPackage_packageType :: Lens.Lens' CreatePackage PackageType
createPackage_packageType :: (PackageType -> f PackageType) -> CreatePackage -> f CreatePackage
createPackage_packageType = (CreatePackage -> PackageType)
-> (CreatePackage -> PackageType -> CreatePackage)
-> Lens CreatePackage CreatePackage PackageType PackageType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackage' {PackageType
packageType :: PackageType
$sel:packageType:CreatePackage' :: CreatePackage -> PackageType
packageType} -> PackageType
packageType) (\s :: CreatePackage
s@CreatePackage' {} PackageType
a -> CreatePackage
s {$sel:packageType:CreatePackage' :: PackageType
packageType = PackageType
a} :: CreatePackage)

-- | The Amazon S3 location from which to import the package.
createPackage_packageSource :: Lens.Lens' CreatePackage PackageSource
createPackage_packageSource :: (PackageSource -> f PackageSource)
-> CreatePackage -> f CreatePackage
createPackage_packageSource = (CreatePackage -> PackageSource)
-> (CreatePackage -> PackageSource -> CreatePackage)
-> Lens CreatePackage CreatePackage PackageSource PackageSource
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackage' {PackageSource
packageSource :: PackageSource
$sel:packageSource:CreatePackage' :: CreatePackage -> PackageSource
packageSource} -> PackageSource
packageSource) (\s :: CreatePackage
s@CreatePackage' {} PackageSource
a -> CreatePackage
s {$sel:packageSource:CreatePackage' :: PackageSource
packageSource = PackageSource
a} :: CreatePackage)

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

instance Prelude.NFData CreatePackage

instance Core.ToHeaders CreatePackage where
  toHeaders :: CreatePackage -> ResponseHeaders
toHeaders = ResponseHeaders -> CreatePackage -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON CreatePackage where
  toJSON :: CreatePackage -> Value
toJSON CreatePackage' {Maybe Text
Text
PackageSource
PackageType
packageSource :: PackageSource
packageType :: PackageType
packageName :: Text
packageDescription :: Maybe Text
$sel:packageSource:CreatePackage' :: CreatePackage -> PackageSource
$sel:packageType:CreatePackage' :: CreatePackage -> PackageType
$sel:packageName:CreatePackage' :: CreatePackage -> Text
$sel:packageDescription:CreatePackage' :: CreatePackage -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PackageDescription" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
packageDescription,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PackageName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
packageName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PackageType" Text -> PackageType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PackageType
packageType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PackageSource" Text -> PackageSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PackageSource
packageSource)
          ]
      )

instance Core.ToPath CreatePackage where
  toPath :: CreatePackage -> ByteString
toPath = ByteString -> CreatePackage -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/2021-01-01/packages"

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

-- | Container for the response returned by the @ CreatePackage @ operation.
--
-- /See:/ 'newCreatePackageResponse' smart constructor.
data CreatePackageResponse = CreatePackageResponse'
  { -- | Information about the package.
    CreatePackageResponse -> Maybe PackageDetails
packageDetails :: Prelude.Maybe PackageDetails,
    -- | The response's http status code.
    CreatePackageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreatePackageResponse -> CreatePackageResponse -> Bool
(CreatePackageResponse -> CreatePackageResponse -> Bool)
-> (CreatePackageResponse -> CreatePackageResponse -> Bool)
-> Eq CreatePackageResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePackageResponse -> CreatePackageResponse -> Bool
$c/= :: CreatePackageResponse -> CreatePackageResponse -> Bool
== :: CreatePackageResponse -> CreatePackageResponse -> Bool
$c== :: CreatePackageResponse -> CreatePackageResponse -> Bool
Prelude.Eq, ReadPrec [CreatePackageResponse]
ReadPrec CreatePackageResponse
Int -> ReadS CreatePackageResponse
ReadS [CreatePackageResponse]
(Int -> ReadS CreatePackageResponse)
-> ReadS [CreatePackageResponse]
-> ReadPrec CreatePackageResponse
-> ReadPrec [CreatePackageResponse]
-> Read CreatePackageResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePackageResponse]
$creadListPrec :: ReadPrec [CreatePackageResponse]
readPrec :: ReadPrec CreatePackageResponse
$creadPrec :: ReadPrec CreatePackageResponse
readList :: ReadS [CreatePackageResponse]
$creadList :: ReadS [CreatePackageResponse]
readsPrec :: Int -> ReadS CreatePackageResponse
$creadsPrec :: Int -> ReadS CreatePackageResponse
Prelude.Read, Int -> CreatePackageResponse -> ShowS
[CreatePackageResponse] -> ShowS
CreatePackageResponse -> String
(Int -> CreatePackageResponse -> ShowS)
-> (CreatePackageResponse -> String)
-> ([CreatePackageResponse] -> ShowS)
-> Show CreatePackageResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePackageResponse] -> ShowS
$cshowList :: [CreatePackageResponse] -> ShowS
show :: CreatePackageResponse -> String
$cshow :: CreatePackageResponse -> String
showsPrec :: Int -> CreatePackageResponse -> ShowS
$cshowsPrec :: Int -> CreatePackageResponse -> ShowS
Prelude.Show, (forall x. CreatePackageResponse -> Rep CreatePackageResponse x)
-> (forall x. Rep CreatePackageResponse x -> CreatePackageResponse)
-> Generic CreatePackageResponse
forall x. Rep CreatePackageResponse x -> CreatePackageResponse
forall x. CreatePackageResponse -> Rep CreatePackageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePackageResponse x -> CreatePackageResponse
$cfrom :: forall x. CreatePackageResponse -> Rep CreatePackageResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreatePackageResponse' 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:
--
-- 'packageDetails', 'createPackageResponse_packageDetails' - Information about the package.
--
-- 'httpStatus', 'createPackageResponse_httpStatus' - The response's http status code.
newCreatePackageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreatePackageResponse
newCreatePackageResponse :: Int -> CreatePackageResponse
newCreatePackageResponse Int
pHttpStatus_ =
  CreatePackageResponse' :: Maybe PackageDetails -> Int -> CreatePackageResponse
CreatePackageResponse'
    { $sel:packageDetails:CreatePackageResponse' :: Maybe PackageDetails
packageDetails =
        Maybe PackageDetails
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreatePackageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the package.
createPackageResponse_packageDetails :: Lens.Lens' CreatePackageResponse (Prelude.Maybe PackageDetails)
createPackageResponse_packageDetails :: (Maybe PackageDetails -> f (Maybe PackageDetails))
-> CreatePackageResponse -> f CreatePackageResponse
createPackageResponse_packageDetails = (CreatePackageResponse -> Maybe PackageDetails)
-> (CreatePackageResponse
    -> Maybe PackageDetails -> CreatePackageResponse)
-> Lens
     CreatePackageResponse
     CreatePackageResponse
     (Maybe PackageDetails)
     (Maybe PackageDetails)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackageResponse' {Maybe PackageDetails
packageDetails :: Maybe PackageDetails
$sel:packageDetails:CreatePackageResponse' :: CreatePackageResponse -> Maybe PackageDetails
packageDetails} -> Maybe PackageDetails
packageDetails) (\s :: CreatePackageResponse
s@CreatePackageResponse' {} Maybe PackageDetails
a -> CreatePackageResponse
s {$sel:packageDetails:CreatePackageResponse' :: Maybe PackageDetails
packageDetails = Maybe PackageDetails
a} :: CreatePackageResponse)

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

instance Prelude.NFData CreatePackageResponse