{-# 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.Panorama.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)
--
-- Creates a package and storage location in an Amazon S3 access point.
module Amazonka.Panorama.CreatePackage
  ( -- * Creating a Request
    CreatePackage (..),
    newCreatePackage,

    -- * Request Lenses
    createPackage_tags,
    createPackage_packageName,

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

    -- * Response Lenses
    createPackageResponse_packageId,
    createPackageResponse_arn,
    createPackageResponse_httpStatus,
    createPackageResponse_storageLocation,
  )
where

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

-- | /See:/ 'newCreatePackage' smart constructor.
data CreatePackage = CreatePackage'
  { -- | Tags for the package.
    CreatePackage -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A name for the package.
    CreatePackage -> Text
packageName :: Prelude.Text
  }
  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:
--
-- 'tags', 'createPackage_tags' - Tags for the package.
--
-- 'packageName', 'createPackage_packageName' - A name for the package.
newCreatePackage ::
  -- | 'packageName'
  Prelude.Text ->
  CreatePackage
newCreatePackage :: Text -> CreatePackage
newCreatePackage Text
pPackageName_ =
  CreatePackage' :: Maybe (HashMap Text Text) -> Text -> CreatePackage
CreatePackage'
    { $sel:tags:CreatePackage' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:packageName:CreatePackage' :: Text
packageName = Text
pPackageName_
    }

-- | Tags for the package.
createPackage_tags :: Lens.Lens' CreatePackage (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createPackage_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreatePackage -> f CreatePackage
createPackage_tags = (CreatePackage -> Maybe (HashMap Text Text))
-> (CreatePackage -> Maybe (HashMap Text Text) -> CreatePackage)
-> Lens
     CreatePackage
     CreatePackage
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackage' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreatePackage' :: CreatePackage -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreatePackage
s@CreatePackage' {} Maybe (HashMap Text Text)
a -> CreatePackage
s {$sel:tags:CreatePackage' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreatePackage) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreatePackage -> f CreatePackage)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreatePackage
-> f CreatePackage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A name 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)

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 Text
-> Maybe Text -> Int -> StorageLocation -> CreatePackageResponse
CreatePackageResponse'
            (Maybe Text
 -> Maybe Text -> Int -> StorageLocation -> CreatePackageResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text -> Int -> StorageLocation -> CreatePackageResponse)
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
"PackageId")
            Either
  String
  (Maybe Text -> Int -> StorageLocation -> CreatePackageResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StorageLocation -> CreatePackageResponse)
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
"Arn")
            Either String (Int -> StorageLocation -> CreatePackageResponse)
-> Either String Int
-> Either String (StorageLocation -> 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))
            Either String (StorageLocation -> CreatePackageResponse)
-> Either String StorageLocation
-> Either String CreatePackageResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String StorageLocation
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"StorageLocation")
      )

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] -> 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 CreatePackage where
  toJSON :: CreatePackage -> Value
toJSON CreatePackage' {Maybe (HashMap Text Text)
Text
packageName :: Text
tags :: Maybe (HashMap Text Text)
$sel:packageName:CreatePackage' :: CreatePackage -> Text
$sel:tags:CreatePackage' :: CreatePackage -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags,
            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)
          ]
      )

instance Core.ToPath CreatePackage where
  toPath :: CreatePackage -> ByteString
toPath = ByteString -> CreatePackage -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/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

-- | /See:/ 'newCreatePackageResponse' smart constructor.
data CreatePackageResponse = CreatePackageResponse'
  { -- | The package\'s ID.
    CreatePackageResponse -> Maybe Text
packageId :: Prelude.Maybe Prelude.Text,
    -- | The package\'s ARN.
    CreatePackageResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreatePackageResponse -> Int
httpStatus :: Prelude.Int,
    -- | The package\'s storage location.
    CreatePackageResponse -> StorageLocation
storageLocation :: StorageLocation
  }
  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:
--
-- 'packageId', 'createPackageResponse_packageId' - The package\'s ID.
--
-- 'arn', 'createPackageResponse_arn' - The package\'s ARN.
--
-- 'httpStatus', 'createPackageResponse_httpStatus' - The response's http status code.
--
-- 'storageLocation', 'createPackageResponse_storageLocation' - The package\'s storage location.
newCreatePackageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'storageLocation'
  StorageLocation ->
  CreatePackageResponse
newCreatePackageResponse :: Int -> StorageLocation -> CreatePackageResponse
newCreatePackageResponse
  Int
pHttpStatus_
  StorageLocation
pStorageLocation_ =
    CreatePackageResponse' :: Maybe Text
-> Maybe Text -> Int -> StorageLocation -> CreatePackageResponse
CreatePackageResponse'
      { $sel:packageId:CreatePackageResponse' :: Maybe Text
packageId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:arn:CreatePackageResponse' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:httpStatus:CreatePackageResponse' :: Int
httpStatus = Int
pHttpStatus_,
        $sel:storageLocation:CreatePackageResponse' :: StorageLocation
storageLocation = StorageLocation
pStorageLocation_
      }

-- | The package\'s ID.
createPackageResponse_packageId :: Lens.Lens' CreatePackageResponse (Prelude.Maybe Prelude.Text)
createPackageResponse_packageId :: (Maybe Text -> f (Maybe Text))
-> CreatePackageResponse -> f CreatePackageResponse
createPackageResponse_packageId = (CreatePackageResponse -> Maybe Text)
-> (CreatePackageResponse -> Maybe Text -> CreatePackageResponse)
-> Lens
     CreatePackageResponse
     CreatePackageResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackageResponse' {Maybe Text
packageId :: Maybe Text
$sel:packageId:CreatePackageResponse' :: CreatePackageResponse -> Maybe Text
packageId} -> Maybe Text
packageId) (\s :: CreatePackageResponse
s@CreatePackageResponse' {} Maybe Text
a -> CreatePackageResponse
s {$sel:packageId:CreatePackageResponse' :: Maybe Text
packageId = Maybe Text
a} :: CreatePackageResponse)

-- | The package\'s ARN.
createPackageResponse_arn :: Lens.Lens' CreatePackageResponse (Prelude.Maybe Prelude.Text)
createPackageResponse_arn :: (Maybe Text -> f (Maybe Text))
-> CreatePackageResponse -> f CreatePackageResponse
createPackageResponse_arn = (CreatePackageResponse -> Maybe Text)
-> (CreatePackageResponse -> Maybe Text -> CreatePackageResponse)
-> Lens
     CreatePackageResponse
     CreatePackageResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackageResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:CreatePackageResponse' :: CreatePackageResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: CreatePackageResponse
s@CreatePackageResponse' {} Maybe Text
a -> CreatePackageResponse
s {$sel:arn:CreatePackageResponse' :: Maybe Text
arn = Maybe Text
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)

-- | The package\'s storage location.
createPackageResponse_storageLocation :: Lens.Lens' CreatePackageResponse StorageLocation
createPackageResponse_storageLocation :: (StorageLocation -> f StorageLocation)
-> CreatePackageResponse -> f CreatePackageResponse
createPackageResponse_storageLocation = (CreatePackageResponse -> StorageLocation)
-> (CreatePackageResponse
    -> StorageLocation -> CreatePackageResponse)
-> Lens
     CreatePackageResponse
     CreatePackageResponse
     StorageLocation
     StorageLocation
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePackageResponse' {StorageLocation
storageLocation :: StorageLocation
$sel:storageLocation:CreatePackageResponse' :: CreatePackageResponse -> StorageLocation
storageLocation} -> StorageLocation
storageLocation) (\s :: CreatePackageResponse
s@CreatePackageResponse' {} StorageLocation
a -> CreatePackageResponse
s {$sel:storageLocation:CreatePackageResponse' :: StorageLocation
storageLocation = StorageLocation
a} :: CreatePackageResponse)

instance Prelude.NFData CreatePackageResponse