{-# 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.DataBrew.UpdateRuleset
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates specified ruleset.
module Amazonka.DataBrew.UpdateRuleset
  ( -- * Creating a Request
    UpdateRuleset (..),
    newUpdateRuleset,

    -- * Request Lenses
    updateRuleset_description,
    updateRuleset_name,
    updateRuleset_rules,

    -- * Destructuring the Response
    UpdateRulesetResponse (..),
    newUpdateRulesetResponse,

    -- * Response Lenses
    updateRulesetResponse_httpStatus,
    updateRulesetResponse_name,
  )
where

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

-- | /See:/ 'newUpdateRuleset' smart constructor.
data UpdateRuleset = UpdateRuleset'
  { -- | The description of the ruleset.
    UpdateRuleset -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the ruleset to be updated.
    UpdateRuleset -> Text
name :: Prelude.Text,
    -- | A list of rules that are defined with the ruleset. A rule includes one
    -- or more checks to be validated on a DataBrew dataset.
    UpdateRuleset -> NonEmpty Rule
rules :: Prelude.NonEmpty Rule
  }
  deriving (UpdateRuleset -> UpdateRuleset -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRuleset -> UpdateRuleset -> Bool
$c/= :: UpdateRuleset -> UpdateRuleset -> Bool
== :: UpdateRuleset -> UpdateRuleset -> Bool
$c== :: UpdateRuleset -> UpdateRuleset -> Bool
Prelude.Eq, ReadPrec [UpdateRuleset]
ReadPrec UpdateRuleset
Int -> ReadS UpdateRuleset
ReadS [UpdateRuleset]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateRuleset]
$creadListPrec :: ReadPrec [UpdateRuleset]
readPrec :: ReadPrec UpdateRuleset
$creadPrec :: ReadPrec UpdateRuleset
readList :: ReadS [UpdateRuleset]
$creadList :: ReadS [UpdateRuleset]
readsPrec :: Int -> ReadS UpdateRuleset
$creadsPrec :: Int -> ReadS UpdateRuleset
Prelude.Read, Int -> UpdateRuleset -> ShowS
[UpdateRuleset] -> ShowS
UpdateRuleset -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRuleset] -> ShowS
$cshowList :: [UpdateRuleset] -> ShowS
show :: UpdateRuleset -> String
$cshow :: UpdateRuleset -> String
showsPrec :: Int -> UpdateRuleset -> ShowS
$cshowsPrec :: Int -> UpdateRuleset -> ShowS
Prelude.Show, forall x. Rep UpdateRuleset x -> UpdateRuleset
forall x. UpdateRuleset -> Rep UpdateRuleset x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRuleset x -> UpdateRuleset
$cfrom :: forall x. UpdateRuleset -> Rep UpdateRuleset x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRuleset' 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:
--
-- 'description', 'updateRuleset_description' - The description of the ruleset.
--
-- 'name', 'updateRuleset_name' - The name of the ruleset to be updated.
--
-- 'rules', 'updateRuleset_rules' - A list of rules that are defined with the ruleset. A rule includes one
-- or more checks to be validated on a DataBrew dataset.
newUpdateRuleset ::
  -- | 'name'
  Prelude.Text ->
  -- | 'rules'
  Prelude.NonEmpty Rule ->
  UpdateRuleset
newUpdateRuleset :: Text -> NonEmpty Rule -> UpdateRuleset
newUpdateRuleset Text
pName_ NonEmpty Rule
pRules_ =
  UpdateRuleset'
    { $sel:description:UpdateRuleset' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateRuleset' :: Text
name = Text
pName_,
      $sel:rules:UpdateRuleset' :: NonEmpty Rule
rules = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Rule
pRules_
    }

-- | The description of the ruleset.
updateRuleset_description :: Lens.Lens' UpdateRuleset (Prelude.Maybe Prelude.Text)
updateRuleset_description :: Lens' UpdateRuleset (Maybe Text)
updateRuleset_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRuleset' {Maybe Text
description :: Maybe Text
$sel:description:UpdateRuleset' :: UpdateRuleset -> Maybe Text
description} -> Maybe Text
description) (\s :: UpdateRuleset
s@UpdateRuleset' {} Maybe Text
a -> UpdateRuleset
s {$sel:description:UpdateRuleset' :: Maybe Text
description = Maybe Text
a} :: UpdateRuleset)

-- | The name of the ruleset to be updated.
updateRuleset_name :: Lens.Lens' UpdateRuleset Prelude.Text
updateRuleset_name :: Lens' UpdateRuleset Text
updateRuleset_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRuleset' {Text
name :: Text
$sel:name:UpdateRuleset' :: UpdateRuleset -> Text
name} -> Text
name) (\s :: UpdateRuleset
s@UpdateRuleset' {} Text
a -> UpdateRuleset
s {$sel:name:UpdateRuleset' :: Text
name = Text
a} :: UpdateRuleset)

-- | A list of rules that are defined with the ruleset. A rule includes one
-- or more checks to be validated on a DataBrew dataset.
updateRuleset_rules :: Lens.Lens' UpdateRuleset (Prelude.NonEmpty Rule)
updateRuleset_rules :: Lens' UpdateRuleset (NonEmpty Rule)
updateRuleset_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRuleset' {NonEmpty Rule
rules :: NonEmpty Rule
$sel:rules:UpdateRuleset' :: UpdateRuleset -> NonEmpty Rule
rules} -> NonEmpty Rule
rules) (\s :: UpdateRuleset
s@UpdateRuleset' {} NonEmpty Rule
a -> UpdateRuleset
s {$sel:rules:UpdateRuleset' :: NonEmpty Rule
rules = NonEmpty Rule
a} :: UpdateRuleset) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest UpdateRuleset where
  type
    AWSResponse UpdateRuleset =
      UpdateRulesetResponse
  request :: (Service -> Service) -> UpdateRuleset -> Request UpdateRuleset
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateRuleset
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateRuleset)))
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 ->
          Int -> Text -> UpdateRulesetResponse
UpdateRulesetResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"Name")
      )

instance Prelude.Hashable UpdateRuleset where
  hashWithSalt :: Int -> UpdateRuleset -> Int
hashWithSalt Int
_salt UpdateRuleset' {Maybe Text
NonEmpty Rule
Text
rules :: NonEmpty Rule
name :: Text
description :: Maybe Text
$sel:rules:UpdateRuleset' :: UpdateRuleset -> NonEmpty Rule
$sel:name:UpdateRuleset' :: UpdateRuleset -> Text
$sel:description:UpdateRuleset' :: UpdateRuleset -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Rule
rules

instance Prelude.NFData UpdateRuleset where
  rnf :: UpdateRuleset -> ()
rnf UpdateRuleset' {Maybe Text
NonEmpty Rule
Text
rules :: NonEmpty Rule
name :: Text
description :: Maybe Text
$sel:rules:UpdateRuleset' :: UpdateRuleset -> NonEmpty Rule
$sel:name:UpdateRuleset' :: UpdateRuleset -> Text
$sel:description:UpdateRuleset' :: UpdateRuleset -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      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 NonEmpty Rule
rules

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

instance Data.ToJSON UpdateRuleset where
  toJSON :: UpdateRuleset -> Value
toJSON UpdateRuleset' {Maybe Text
NonEmpty Rule
Text
rules :: NonEmpty Rule
name :: Text
description :: Maybe Text
$sel:rules:UpdateRuleset' :: UpdateRuleset -> NonEmpty Rule
$sel:name:UpdateRuleset' :: UpdateRuleset -> Text
$sel:description:UpdateRuleset' :: UpdateRuleset -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Description" 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 Text
description,
            forall a. a -> Maybe a
Prelude.Just (Key
"Rules" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Rule
rules)
          ]
      )

instance Data.ToPath UpdateRuleset where
  toPath :: UpdateRuleset -> ByteString
toPath UpdateRuleset' {Maybe Text
NonEmpty Rule
Text
rules :: NonEmpty Rule
name :: Text
description :: Maybe Text
$sel:rules:UpdateRuleset' :: UpdateRuleset -> NonEmpty Rule
$sel:name:UpdateRuleset' :: UpdateRuleset -> Text
$sel:description:UpdateRuleset' :: UpdateRuleset -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/rulesets/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
name]

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

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

-- |
-- Create a value of 'UpdateRulesetResponse' 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:
--
-- 'httpStatus', 'updateRulesetResponse_httpStatus' - The response's http status code.
--
-- 'name', 'updateRulesetResponse_name' - The name of the updated ruleset.
newUpdateRulesetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'name'
  Prelude.Text ->
  UpdateRulesetResponse
newUpdateRulesetResponse :: Int -> Text -> UpdateRulesetResponse
newUpdateRulesetResponse Int
pHttpStatus_ Text
pName_ =
  UpdateRulesetResponse'
    { $sel:httpStatus:UpdateRulesetResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:name:UpdateRulesetResponse' :: Text
name = Text
pName_
    }

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

-- | The name of the updated ruleset.
updateRulesetResponse_name :: Lens.Lens' UpdateRulesetResponse Prelude.Text
updateRulesetResponse_name :: Lens' UpdateRulesetResponse Text
updateRulesetResponse_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRulesetResponse' {Text
name :: Text
$sel:name:UpdateRulesetResponse' :: UpdateRulesetResponse -> Text
name} -> Text
name) (\s :: UpdateRulesetResponse
s@UpdateRulesetResponse' {} Text
a -> UpdateRulesetResponse
s {$sel:name:UpdateRulesetResponse' :: Text
name = Text
a} :: UpdateRulesetResponse)

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