{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Glue.Types.SchemaChangePolicy
-- 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)
module Amazonka.Glue.Types.SchemaChangePolicy where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.DeleteBehavior
import Amazonka.Glue.Types.UpdateBehavior
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A policy that specifies update and deletion behaviors for the crawler.
--
-- /See:/ 'newSchemaChangePolicy' smart constructor.
data SchemaChangePolicy = SchemaChangePolicy'
  { -- | The deletion behavior when the crawler finds a deleted object.
    SchemaChangePolicy -> Maybe DeleteBehavior
deleteBehavior :: Prelude.Maybe DeleteBehavior,
    -- | The update behavior when the crawler finds a changed schema.
    SchemaChangePolicy -> Maybe UpdateBehavior
updateBehavior :: Prelude.Maybe UpdateBehavior
  }
  deriving (SchemaChangePolicy -> SchemaChangePolicy -> Bool
(SchemaChangePolicy -> SchemaChangePolicy -> Bool)
-> (SchemaChangePolicy -> SchemaChangePolicy -> Bool)
-> Eq SchemaChangePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaChangePolicy -> SchemaChangePolicy -> Bool
$c/= :: SchemaChangePolicy -> SchemaChangePolicy -> Bool
== :: SchemaChangePolicy -> SchemaChangePolicy -> Bool
$c== :: SchemaChangePolicy -> SchemaChangePolicy -> Bool
Prelude.Eq, ReadPrec [SchemaChangePolicy]
ReadPrec SchemaChangePolicy
Int -> ReadS SchemaChangePolicy
ReadS [SchemaChangePolicy]
(Int -> ReadS SchemaChangePolicy)
-> ReadS [SchemaChangePolicy]
-> ReadPrec SchemaChangePolicy
-> ReadPrec [SchemaChangePolicy]
-> Read SchemaChangePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SchemaChangePolicy]
$creadListPrec :: ReadPrec [SchemaChangePolicy]
readPrec :: ReadPrec SchemaChangePolicy
$creadPrec :: ReadPrec SchemaChangePolicy
readList :: ReadS [SchemaChangePolicy]
$creadList :: ReadS [SchemaChangePolicy]
readsPrec :: Int -> ReadS SchemaChangePolicy
$creadsPrec :: Int -> ReadS SchemaChangePolicy
Prelude.Read, Int -> SchemaChangePolicy -> ShowS
[SchemaChangePolicy] -> ShowS
SchemaChangePolicy -> String
(Int -> SchemaChangePolicy -> ShowS)
-> (SchemaChangePolicy -> String)
-> ([SchemaChangePolicy] -> ShowS)
-> Show SchemaChangePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaChangePolicy] -> ShowS
$cshowList :: [SchemaChangePolicy] -> ShowS
show :: SchemaChangePolicy -> String
$cshow :: SchemaChangePolicy -> String
showsPrec :: Int -> SchemaChangePolicy -> ShowS
$cshowsPrec :: Int -> SchemaChangePolicy -> ShowS
Prelude.Show, (forall x. SchemaChangePolicy -> Rep SchemaChangePolicy x)
-> (forall x. Rep SchemaChangePolicy x -> SchemaChangePolicy)
-> Generic SchemaChangePolicy
forall x. Rep SchemaChangePolicy x -> SchemaChangePolicy
forall x. SchemaChangePolicy -> Rep SchemaChangePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SchemaChangePolicy x -> SchemaChangePolicy
$cfrom :: forall x. SchemaChangePolicy -> Rep SchemaChangePolicy x
Prelude.Generic)

-- |
-- Create a value of 'SchemaChangePolicy' 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:
--
-- 'deleteBehavior', 'schemaChangePolicy_deleteBehavior' - The deletion behavior when the crawler finds a deleted object.
--
-- 'updateBehavior', 'schemaChangePolicy_updateBehavior' - The update behavior when the crawler finds a changed schema.
newSchemaChangePolicy ::
  SchemaChangePolicy
newSchemaChangePolicy :: SchemaChangePolicy
newSchemaChangePolicy =
  SchemaChangePolicy' :: Maybe DeleteBehavior -> Maybe UpdateBehavior -> SchemaChangePolicy
SchemaChangePolicy'
    { $sel:deleteBehavior:SchemaChangePolicy' :: Maybe DeleteBehavior
deleteBehavior =
        Maybe DeleteBehavior
forall a. Maybe a
Prelude.Nothing,
      $sel:updateBehavior:SchemaChangePolicy' :: Maybe UpdateBehavior
updateBehavior = Maybe UpdateBehavior
forall a. Maybe a
Prelude.Nothing
    }

-- | The deletion behavior when the crawler finds a deleted object.
schemaChangePolicy_deleteBehavior :: Lens.Lens' SchemaChangePolicy (Prelude.Maybe DeleteBehavior)
schemaChangePolicy_deleteBehavior :: (Maybe DeleteBehavior -> f (Maybe DeleteBehavior))
-> SchemaChangePolicy -> f SchemaChangePolicy
schemaChangePolicy_deleteBehavior = (SchemaChangePolicy -> Maybe DeleteBehavior)
-> (SchemaChangePolicy
    -> Maybe DeleteBehavior -> SchemaChangePolicy)
-> Lens
     SchemaChangePolicy
     SchemaChangePolicy
     (Maybe DeleteBehavior)
     (Maybe DeleteBehavior)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaChangePolicy' {Maybe DeleteBehavior
deleteBehavior :: Maybe DeleteBehavior
$sel:deleteBehavior:SchemaChangePolicy' :: SchemaChangePolicy -> Maybe DeleteBehavior
deleteBehavior} -> Maybe DeleteBehavior
deleteBehavior) (\s :: SchemaChangePolicy
s@SchemaChangePolicy' {} Maybe DeleteBehavior
a -> SchemaChangePolicy
s {$sel:deleteBehavior:SchemaChangePolicy' :: Maybe DeleteBehavior
deleteBehavior = Maybe DeleteBehavior
a} :: SchemaChangePolicy)

-- | The update behavior when the crawler finds a changed schema.
schemaChangePolicy_updateBehavior :: Lens.Lens' SchemaChangePolicy (Prelude.Maybe UpdateBehavior)
schemaChangePolicy_updateBehavior :: (Maybe UpdateBehavior -> f (Maybe UpdateBehavior))
-> SchemaChangePolicy -> f SchemaChangePolicy
schemaChangePolicy_updateBehavior = (SchemaChangePolicy -> Maybe UpdateBehavior)
-> (SchemaChangePolicy
    -> Maybe UpdateBehavior -> SchemaChangePolicy)
-> Lens
     SchemaChangePolicy
     SchemaChangePolicy
     (Maybe UpdateBehavior)
     (Maybe UpdateBehavior)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SchemaChangePolicy' {Maybe UpdateBehavior
updateBehavior :: Maybe UpdateBehavior
$sel:updateBehavior:SchemaChangePolicy' :: SchemaChangePolicy -> Maybe UpdateBehavior
updateBehavior} -> Maybe UpdateBehavior
updateBehavior) (\s :: SchemaChangePolicy
s@SchemaChangePolicy' {} Maybe UpdateBehavior
a -> SchemaChangePolicy
s {$sel:updateBehavior:SchemaChangePolicy' :: Maybe UpdateBehavior
updateBehavior = Maybe UpdateBehavior
a} :: SchemaChangePolicy)

instance Core.FromJSON SchemaChangePolicy where
  parseJSON :: Value -> Parser SchemaChangePolicy
parseJSON =
    String
-> (Object -> Parser SchemaChangePolicy)
-> Value
-> Parser SchemaChangePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SchemaChangePolicy"
      ( \Object
x ->
          Maybe DeleteBehavior -> Maybe UpdateBehavior -> SchemaChangePolicy
SchemaChangePolicy'
            (Maybe DeleteBehavior
 -> Maybe UpdateBehavior -> SchemaChangePolicy)
-> Parser (Maybe DeleteBehavior)
-> Parser (Maybe UpdateBehavior -> SchemaChangePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DeleteBehavior)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DeleteBehavior")
            Parser (Maybe UpdateBehavior -> SchemaChangePolicy)
-> Parser (Maybe UpdateBehavior) -> Parser SchemaChangePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe UpdateBehavior)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UpdateBehavior")
      )

instance Prelude.Hashable SchemaChangePolicy

instance Prelude.NFData SchemaChangePolicy

instance Core.ToJSON SchemaChangePolicy where
  toJSON :: SchemaChangePolicy -> Value
toJSON SchemaChangePolicy' {Maybe DeleteBehavior
Maybe UpdateBehavior
updateBehavior :: Maybe UpdateBehavior
deleteBehavior :: Maybe DeleteBehavior
$sel:updateBehavior:SchemaChangePolicy' :: SchemaChangePolicy -> Maybe UpdateBehavior
$sel:deleteBehavior:SchemaChangePolicy' :: SchemaChangePolicy -> Maybe DeleteBehavior
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DeleteBehavior" Text -> DeleteBehavior -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DeleteBehavior -> Pair) -> Maybe DeleteBehavior -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeleteBehavior
deleteBehavior,
            (Text
"UpdateBehavior" Text -> UpdateBehavior -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (UpdateBehavior -> Pair) -> Maybe UpdateBehavior -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe UpdateBehavior
updateBehavior
          ]
      )