{-# 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.CreateFilter
-- 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 recommendation filter. For more information, see filter.
module Amazonka.Personalize.CreateFilter
  ( -- * Creating a Request
    CreateFilter (..),
    newCreateFilter,

    -- * Request Lenses
    createFilter_name,
    createFilter_datasetGroupArn,
    createFilter_filterExpression,

    -- * Destructuring the Response
    CreateFilterResponse (..),
    newCreateFilterResponse,

    -- * Response Lenses
    createFilterResponse_filterArn,
    createFilterResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateFilter' smart constructor.
data CreateFilter = CreateFilter'
  { -- | The name of the filter to create.
    CreateFilter -> Text
name :: Prelude.Text,
    -- | The ARN of the dataset group that the filter will belong to.
    CreateFilter -> Text
datasetGroupArn :: Prelude.Text,
    -- | The filter expression defines which items are included or excluded from
    -- recommendations. Filter expression must follow specific format rules.
    -- For information about filter expression structure and syntax, see
    -- filter-expressions.
    CreateFilter -> Sensitive Text
filterExpression :: Core.Sensitive Prelude.Text
  }
  deriving (CreateFilter -> CreateFilter -> Bool
(CreateFilter -> CreateFilter -> Bool)
-> (CreateFilter -> CreateFilter -> Bool) -> Eq CreateFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateFilter -> CreateFilter -> Bool
$c/= :: CreateFilter -> CreateFilter -> Bool
== :: CreateFilter -> CreateFilter -> Bool
$c== :: CreateFilter -> CreateFilter -> Bool
Prelude.Eq, Int -> CreateFilter -> ShowS
[CreateFilter] -> ShowS
CreateFilter -> String
(Int -> CreateFilter -> ShowS)
-> (CreateFilter -> String)
-> ([CreateFilter] -> ShowS)
-> Show CreateFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateFilter] -> ShowS
$cshowList :: [CreateFilter] -> ShowS
show :: CreateFilter -> String
$cshow :: CreateFilter -> String
showsPrec :: Int -> CreateFilter -> ShowS
$cshowsPrec :: Int -> CreateFilter -> ShowS
Prelude.Show, (forall x. CreateFilter -> Rep CreateFilter x)
-> (forall x. Rep CreateFilter x -> CreateFilter)
-> Generic CreateFilter
forall x. Rep CreateFilter x -> CreateFilter
forall x. CreateFilter -> Rep CreateFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateFilter x -> CreateFilter
$cfrom :: forall x. CreateFilter -> Rep CreateFilter x
Prelude.Generic)

-- |
-- Create a value of 'CreateFilter' 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:
--
-- 'name', 'createFilter_name' - The name of the filter to create.
--
-- 'datasetGroupArn', 'createFilter_datasetGroupArn' - The ARN of the dataset group that the filter will belong to.
--
-- 'filterExpression', 'createFilter_filterExpression' - The filter expression defines which items are included or excluded from
-- recommendations. Filter expression must follow specific format rules.
-- For information about filter expression structure and syntax, see
-- filter-expressions.
newCreateFilter ::
  -- | 'name'
  Prelude.Text ->
  -- | 'datasetGroupArn'
  Prelude.Text ->
  -- | 'filterExpression'
  Prelude.Text ->
  CreateFilter
newCreateFilter :: Text -> Text -> Text -> CreateFilter
newCreateFilter
  Text
pName_
  Text
pDatasetGroupArn_
  Text
pFilterExpression_ =
    CreateFilter' :: Text -> Text -> Sensitive Text -> CreateFilter
CreateFilter'
      { $sel:name:CreateFilter' :: Text
name = Text
pName_,
        $sel:datasetGroupArn:CreateFilter' :: Text
datasetGroupArn = Text
pDatasetGroupArn_,
        $sel:filterExpression:CreateFilter' :: Sensitive Text
filterExpression =
          Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pFilterExpression_
      }

-- | The name of the filter to create.
createFilter_name :: Lens.Lens' CreateFilter Prelude.Text
createFilter_name :: (Text -> f Text) -> CreateFilter -> f CreateFilter
createFilter_name = (CreateFilter -> Text)
-> (CreateFilter -> Text -> CreateFilter)
-> Lens CreateFilter CreateFilter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFilter' {Text
name :: Text
$sel:name:CreateFilter' :: CreateFilter -> Text
name} -> Text
name) (\s :: CreateFilter
s@CreateFilter' {} Text
a -> CreateFilter
s {$sel:name:CreateFilter' :: Text
name = Text
a} :: CreateFilter)

-- | The ARN of the dataset group that the filter will belong to.
createFilter_datasetGroupArn :: Lens.Lens' CreateFilter Prelude.Text
createFilter_datasetGroupArn :: (Text -> f Text) -> CreateFilter -> f CreateFilter
createFilter_datasetGroupArn = (CreateFilter -> Text)
-> (CreateFilter -> Text -> CreateFilter)
-> Lens CreateFilter CreateFilter Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFilter' {Text
datasetGroupArn :: Text
$sel:datasetGroupArn:CreateFilter' :: CreateFilter -> Text
datasetGroupArn} -> Text
datasetGroupArn) (\s :: CreateFilter
s@CreateFilter' {} Text
a -> CreateFilter
s {$sel:datasetGroupArn:CreateFilter' :: Text
datasetGroupArn = Text
a} :: CreateFilter)

-- | The filter expression defines which items are included or excluded from
-- recommendations. Filter expression must follow specific format rules.
-- For information about filter expression structure and syntax, see
-- filter-expressions.
createFilter_filterExpression :: Lens.Lens' CreateFilter Prelude.Text
createFilter_filterExpression :: (Text -> f Text) -> CreateFilter -> f CreateFilter
createFilter_filterExpression = (CreateFilter -> Sensitive Text)
-> (CreateFilter -> Sensitive Text -> CreateFilter)
-> Lens CreateFilter CreateFilter (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFilter' {Sensitive Text
filterExpression :: Sensitive Text
$sel:filterExpression:CreateFilter' :: CreateFilter -> Sensitive Text
filterExpression} -> Sensitive Text
filterExpression) (\s :: CreateFilter
s@CreateFilter' {} Sensitive Text
a -> CreateFilter
s {$sel:filterExpression:CreateFilter' :: Sensitive Text
filterExpression = Sensitive Text
a} :: CreateFilter) ((Sensitive Text -> f (Sensitive Text))
 -> CreateFilter -> f CreateFilter)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> CreateFilter
-> f CreateFilter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

instance Prelude.NFData CreateFilter

instance Core.ToHeaders CreateFilter where
  toHeaders :: CreateFilter -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateFilter -> 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
"AmazonPersonalize.CreateFilter" ::
                          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 CreateFilter where
  toJSON :: CreateFilter -> Value
toJSON CreateFilter' {Text
Sensitive Text
filterExpression :: Sensitive Text
datasetGroupArn :: Text
name :: Text
$sel:filterExpression:CreateFilter' :: CreateFilter -> Sensitive Text
$sel:datasetGroupArn:CreateFilter' :: CreateFilter -> Text
$sel:name:CreateFilter' :: CreateFilter -> 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
"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
"datasetGroupArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
datasetGroupArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"filterExpression" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
filterExpression)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateFilterResponse' 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:
--
-- 'filterArn', 'createFilterResponse_filterArn' - The ARN of the new filter.
--
-- 'httpStatus', 'createFilterResponse_httpStatus' - The response's http status code.
newCreateFilterResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateFilterResponse
newCreateFilterResponse :: Int -> CreateFilterResponse
newCreateFilterResponse Int
pHttpStatus_ =
  CreateFilterResponse' :: Maybe Text -> Int -> CreateFilterResponse
CreateFilterResponse'
    { $sel:filterArn:CreateFilterResponse' :: Maybe Text
filterArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateFilterResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the new filter.
createFilterResponse_filterArn :: Lens.Lens' CreateFilterResponse (Prelude.Maybe Prelude.Text)
createFilterResponse_filterArn :: (Maybe Text -> f (Maybe Text))
-> CreateFilterResponse -> f CreateFilterResponse
createFilterResponse_filterArn = (CreateFilterResponse -> Maybe Text)
-> (CreateFilterResponse -> Maybe Text -> CreateFilterResponse)
-> Lens
     CreateFilterResponse CreateFilterResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateFilterResponse' {Maybe Text
filterArn :: Maybe Text
$sel:filterArn:CreateFilterResponse' :: CreateFilterResponse -> Maybe Text
filterArn} -> Maybe Text
filterArn) (\s :: CreateFilterResponse
s@CreateFilterResponse' {} Maybe Text
a -> CreateFilterResponse
s {$sel:filterArn:CreateFilterResponse' :: Maybe Text
filterArn = Maybe Text
a} :: CreateFilterResponse)

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

instance Prelude.NFData CreateFilterResponse