{-# 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.Personalize.CreateSchema
-- 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 an Amazon Personalize schema from the specified schema string.
-- The schema you create must be in Avro JSON format.
--
-- Amazon Personalize recognizes three schema variants. Each schema is
-- associated with a dataset type and has a set of required field and
-- keywords. If you are creating a schema for a dataset in a Domain dataset
-- group, you provide the domain of the Domain dataset group. You specify a
-- schema when you call
-- <https://docs.aws.amazon.com/personalize/latest/dg/API_CreateDataset.html CreateDataset>.
--
-- __Related APIs__
--
-- -   <https://docs.aws.amazon.com/personalize/latest/dg/API_ListSchemas.html ListSchemas>
--
-- -   <https://docs.aws.amazon.com/personalize/latest/dg/API_DescribeSchema.html DescribeSchema>
--
-- -   <https://docs.aws.amazon.com/personalize/latest/dg/API_DeleteSchema.html DeleteSchema>
module Amazonka.Personalize.CreateSchema
  ( -- * Creating a Request
    CreateSchema (..),
    newCreateSchema,

    -- * Request Lenses
    createSchema_domain,
    createSchema_name,
    createSchema_schema,

    -- * Destructuring the Response
    CreateSchemaResponse (..),
    newCreateSchemaResponse,

    -- * Response Lenses
    createSchemaResponse_schemaArn,
    createSchemaResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Personalize.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateSchema' smart constructor.
data CreateSchema = CreateSchema'
  { -- | The domain for the schema. If you are creating a schema for a dataset in
    -- a Domain dataset group, specify the domain you chose when you created
    -- the Domain dataset group.
    CreateSchema -> Maybe Domain
domain :: Prelude.Maybe Domain,
    -- | The name for the schema.
    CreateSchema -> Text
name :: Prelude.Text,
    -- | A schema in Avro JSON format.
    CreateSchema -> Text
schema :: Prelude.Text
  }
  deriving (CreateSchema -> CreateSchema -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateSchema -> CreateSchema -> Bool
$c/= :: CreateSchema -> CreateSchema -> Bool
== :: CreateSchema -> CreateSchema -> Bool
$c== :: CreateSchema -> CreateSchema -> Bool
Prelude.Eq, ReadPrec [CreateSchema]
ReadPrec CreateSchema
Int -> ReadS CreateSchema
ReadS [CreateSchema]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateSchema]
$creadListPrec :: ReadPrec [CreateSchema]
readPrec :: ReadPrec CreateSchema
$creadPrec :: ReadPrec CreateSchema
readList :: ReadS [CreateSchema]
$creadList :: ReadS [CreateSchema]
readsPrec :: Int -> ReadS CreateSchema
$creadsPrec :: Int -> ReadS CreateSchema
Prelude.Read, Int -> CreateSchema -> ShowS
[CreateSchema] -> ShowS
CreateSchema -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateSchema] -> ShowS
$cshowList :: [CreateSchema] -> ShowS
show :: CreateSchema -> String
$cshow :: CreateSchema -> String
showsPrec :: Int -> CreateSchema -> ShowS
$cshowsPrec :: Int -> CreateSchema -> ShowS
Prelude.Show, forall x. Rep CreateSchema x -> CreateSchema
forall x. CreateSchema -> Rep CreateSchema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateSchema x -> CreateSchema
$cfrom :: forall x. CreateSchema -> Rep CreateSchema x
Prelude.Generic)

-- |
-- Create a value of 'CreateSchema' 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:
--
-- 'domain', 'createSchema_domain' - The domain for the schema. If you are creating a schema for a dataset in
-- a Domain dataset group, specify the domain you chose when you created
-- the Domain dataset group.
--
-- 'name', 'createSchema_name' - The name for the schema.
--
-- 'schema', 'createSchema_schema' - A schema in Avro JSON format.
newCreateSchema ::
  -- | 'name'
  Prelude.Text ->
  -- | 'schema'
  Prelude.Text ->
  CreateSchema
newCreateSchema :: Text -> Text -> CreateSchema
newCreateSchema Text
pName_ Text
pSchema_ =
  CreateSchema'
    { $sel:domain:CreateSchema' :: Maybe Domain
domain = forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateSchema' :: Text
name = Text
pName_,
      $sel:schema:CreateSchema' :: Text
schema = Text
pSchema_
    }

-- | The domain for the schema. If you are creating a schema for a dataset in
-- a Domain dataset group, specify the domain you chose when you created
-- the Domain dataset group.
createSchema_domain :: Lens.Lens' CreateSchema (Prelude.Maybe Domain)
createSchema_domain :: Lens' CreateSchema (Maybe Domain)
createSchema_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchema' {Maybe Domain
domain :: Maybe Domain
$sel:domain:CreateSchema' :: CreateSchema -> Maybe Domain
domain} -> Maybe Domain
domain) (\s :: CreateSchema
s@CreateSchema' {} Maybe Domain
a -> CreateSchema
s {$sel:domain:CreateSchema' :: Maybe Domain
domain = Maybe Domain
a} :: CreateSchema)

-- | The name for the schema.
createSchema_name :: Lens.Lens' CreateSchema Prelude.Text
createSchema_name :: Lens' CreateSchema Text
createSchema_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchema' {Text
name :: Text
$sel:name:CreateSchema' :: CreateSchema -> Text
name} -> Text
name) (\s :: CreateSchema
s@CreateSchema' {} Text
a -> CreateSchema
s {$sel:name:CreateSchema' :: Text
name = Text
a} :: CreateSchema)

-- | A schema in Avro JSON format.
createSchema_schema :: Lens.Lens' CreateSchema Prelude.Text
createSchema_schema :: Lens' CreateSchema Text
createSchema_schema = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchema' {Text
schema :: Text
$sel:schema:CreateSchema' :: CreateSchema -> Text
schema} -> Text
schema) (\s :: CreateSchema
s@CreateSchema' {} Text
a -> CreateSchema
s {$sel:schema:CreateSchema' :: Text
schema = Text
a} :: CreateSchema)

instance Core.AWSRequest CreateSchema where
  type AWSResponse CreateSchema = CreateSchemaResponse
  request :: (Service -> Service) -> CreateSchema -> Request CreateSchema
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 CreateSchema
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateSchema)))
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 -> CreateSchemaResponse
CreateSchemaResponse'
            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
"schemaArn")
            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 CreateSchema where
  hashWithSalt :: Int -> CreateSchema -> Int
hashWithSalt Int
_salt CreateSchema' {Maybe Domain
Text
schema :: Text
name :: Text
domain :: Maybe Domain
$sel:schema:CreateSchema' :: CreateSchema -> Text
$sel:name:CreateSchema' :: CreateSchema -> Text
$sel:domain:CreateSchema' :: CreateSchema -> Maybe Domain
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Domain
domain
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
schema

instance Prelude.NFData CreateSchema where
  rnf :: CreateSchema -> ()
rnf CreateSchema' {Maybe Domain
Text
schema :: Text
name :: Text
domain :: Maybe Domain
$sel:schema:CreateSchema' :: CreateSchema -> Text
$sel:name:CreateSchema' :: CreateSchema -> Text
$sel:domain:CreateSchema' :: CreateSchema -> Maybe Domain
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Domain
domain
      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 Text
schema

instance Data.ToHeaders CreateSchema where
  toHeaders :: CreateSchema -> 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
"AmazonPersonalize.CreateSchema" ::
                          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 CreateSchema where
  toJSON :: CreateSchema -> Value
toJSON CreateSchema' {Maybe Domain
Text
schema :: Text
name :: Text
domain :: Maybe Domain
$sel:schema:CreateSchema' :: CreateSchema -> Text
$sel:name:CreateSchema' :: CreateSchema -> Text
$sel:domain:CreateSchema' :: CreateSchema -> Maybe Domain
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"domain" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Domain
domain,
            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
"schema" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
schema)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateSchemaResponse' 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:
--
-- 'schemaArn', 'createSchemaResponse_schemaArn' - The Amazon Resource Name (ARN) of the created schema.
--
-- 'httpStatus', 'createSchemaResponse_httpStatus' - The response's http status code.
newCreateSchemaResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateSchemaResponse
newCreateSchemaResponse :: Int -> CreateSchemaResponse
newCreateSchemaResponse Int
pHttpStatus_ =
  CreateSchemaResponse'
    { $sel:schemaArn:CreateSchemaResponse' :: Maybe Text
schemaArn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateSchemaResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the created schema.
createSchemaResponse_schemaArn :: Lens.Lens' CreateSchemaResponse (Prelude.Maybe Prelude.Text)
createSchemaResponse_schemaArn :: Lens' CreateSchemaResponse (Maybe Text)
createSchemaResponse_schemaArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateSchemaResponse' {Maybe Text
schemaArn :: Maybe Text
$sel:schemaArn:CreateSchemaResponse' :: CreateSchemaResponse -> Maybe Text
schemaArn} -> Maybe Text
schemaArn) (\s :: CreateSchemaResponse
s@CreateSchemaResponse' {} Maybe Text
a -> CreateSchemaResponse
s {$sel:schemaArn:CreateSchemaResponse' :: Maybe Text
schemaArn = Maybe Text
a} :: CreateSchemaResponse)

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

instance Prelude.NFData CreateSchemaResponse where
  rnf :: CreateSchemaResponse -> ()
rnf CreateSchemaResponse' {Int
Maybe Text
httpStatus :: Int
schemaArn :: Maybe Text
$sel:httpStatus:CreateSchemaResponse' :: CreateSchemaResponse -> Int
$sel:schemaArn:CreateSchemaResponse' :: CreateSchemaResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
schemaArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus