{-# 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.IoT.Types.ThingIndexingConfiguration
-- 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.IoT.Types.ThingIndexingConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.Field
import Amazonka.IoT.Types.ThingConnectivityIndexingMode
import Amazonka.IoT.Types.ThingIndexingMode
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The thing indexing configuration. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html Managing Thing Indexing>.
--
-- /See:/ 'newThingIndexingConfiguration' smart constructor.
data ThingIndexingConfiguration = ThingIndexingConfiguration'
  { -- | Contains fields that are indexed and whose types are already known by
    -- the Fleet Indexing service.
    ThingIndexingConfiguration -> Maybe [Field]
managedFields :: Prelude.Maybe [Field],
    -- | Thing connectivity indexing mode. Valid values are:
    --
    -- -   STATUS – Your thing index contains connectivity status. To enable
    --     thing connectivity indexing, /thingIndexMode/ must not be set to
    --     OFF.
    --
    -- -   OFF - Thing connectivity status indexing is disabled.
    ThingIndexingConfiguration -> Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode :: Prelude.Maybe ThingConnectivityIndexingMode,
    -- | Contains custom field names and their data type.
    ThingIndexingConfiguration -> Maybe [Field]
customFields :: Prelude.Maybe [Field],
    -- | Thing indexing mode. Valid values are:
    --
    -- -   REGISTRY – Your thing index contains registry data only.
    --
    -- -   REGISTRY_AND_SHADOW - Your thing index contains registry and shadow
    --     data.
    --
    -- -   OFF - Thing indexing is disabled.
    ThingIndexingConfiguration -> ThingIndexingMode
thingIndexingMode :: ThingIndexingMode
  }
  deriving (ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool
(ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool)
-> (ThingIndexingConfiguration
    -> ThingIndexingConfiguration -> Bool)
-> Eq ThingIndexingConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool
$c/= :: ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool
== :: ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool
$c== :: ThingIndexingConfiguration -> ThingIndexingConfiguration -> Bool
Prelude.Eq, ReadPrec [ThingIndexingConfiguration]
ReadPrec ThingIndexingConfiguration
Int -> ReadS ThingIndexingConfiguration
ReadS [ThingIndexingConfiguration]
(Int -> ReadS ThingIndexingConfiguration)
-> ReadS [ThingIndexingConfiguration]
-> ReadPrec ThingIndexingConfiguration
-> ReadPrec [ThingIndexingConfiguration]
-> Read ThingIndexingConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ThingIndexingConfiguration]
$creadListPrec :: ReadPrec [ThingIndexingConfiguration]
readPrec :: ReadPrec ThingIndexingConfiguration
$creadPrec :: ReadPrec ThingIndexingConfiguration
readList :: ReadS [ThingIndexingConfiguration]
$creadList :: ReadS [ThingIndexingConfiguration]
readsPrec :: Int -> ReadS ThingIndexingConfiguration
$creadsPrec :: Int -> ReadS ThingIndexingConfiguration
Prelude.Read, Int -> ThingIndexingConfiguration -> ShowS
[ThingIndexingConfiguration] -> ShowS
ThingIndexingConfiguration -> String
(Int -> ThingIndexingConfiguration -> ShowS)
-> (ThingIndexingConfiguration -> String)
-> ([ThingIndexingConfiguration] -> ShowS)
-> Show ThingIndexingConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ThingIndexingConfiguration] -> ShowS
$cshowList :: [ThingIndexingConfiguration] -> ShowS
show :: ThingIndexingConfiguration -> String
$cshow :: ThingIndexingConfiguration -> String
showsPrec :: Int -> ThingIndexingConfiguration -> ShowS
$cshowsPrec :: Int -> ThingIndexingConfiguration -> ShowS
Prelude.Show, (forall x.
 ThingIndexingConfiguration -> Rep ThingIndexingConfiguration x)
-> (forall x.
    Rep ThingIndexingConfiguration x -> ThingIndexingConfiguration)
-> Generic ThingIndexingConfiguration
forall x.
Rep ThingIndexingConfiguration x -> ThingIndexingConfiguration
forall x.
ThingIndexingConfiguration -> Rep ThingIndexingConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ThingIndexingConfiguration x -> ThingIndexingConfiguration
$cfrom :: forall x.
ThingIndexingConfiguration -> Rep ThingIndexingConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ThingIndexingConfiguration' 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:
--
-- 'managedFields', 'thingIndexingConfiguration_managedFields' - Contains fields that are indexed and whose types are already known by
-- the Fleet Indexing service.
--
-- 'thingConnectivityIndexingMode', 'thingIndexingConfiguration_thingConnectivityIndexingMode' - Thing connectivity indexing mode. Valid values are:
--
-- -   STATUS – Your thing index contains connectivity status. To enable
--     thing connectivity indexing, /thingIndexMode/ must not be set to
--     OFF.
--
-- -   OFF - Thing connectivity status indexing is disabled.
--
-- 'customFields', 'thingIndexingConfiguration_customFields' - Contains custom field names and their data type.
--
-- 'thingIndexingMode', 'thingIndexingConfiguration_thingIndexingMode' - Thing indexing mode. Valid values are:
--
-- -   REGISTRY – Your thing index contains registry data only.
--
-- -   REGISTRY_AND_SHADOW - Your thing index contains registry and shadow
--     data.
--
-- -   OFF - Thing indexing is disabled.
newThingIndexingConfiguration ::
  -- | 'thingIndexingMode'
  ThingIndexingMode ->
  ThingIndexingConfiguration
newThingIndexingConfiguration :: ThingIndexingMode -> ThingIndexingConfiguration
newThingIndexingConfiguration ThingIndexingMode
pThingIndexingMode_ =
  ThingIndexingConfiguration' :: Maybe [Field]
-> Maybe ThingConnectivityIndexingMode
-> Maybe [Field]
-> ThingIndexingMode
-> ThingIndexingConfiguration
ThingIndexingConfiguration'
    { $sel:managedFields:ThingIndexingConfiguration' :: Maybe [Field]
managedFields =
        Maybe [Field]
forall a. Maybe a
Prelude.Nothing,
      $sel:thingConnectivityIndexingMode:ThingIndexingConfiguration' :: Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode = Maybe ThingConnectivityIndexingMode
forall a. Maybe a
Prelude.Nothing,
      $sel:customFields:ThingIndexingConfiguration' :: Maybe [Field]
customFields = Maybe [Field]
forall a. Maybe a
Prelude.Nothing,
      $sel:thingIndexingMode:ThingIndexingConfiguration' :: ThingIndexingMode
thingIndexingMode = ThingIndexingMode
pThingIndexingMode_
    }

-- | Contains fields that are indexed and whose types are already known by
-- the Fleet Indexing service.
thingIndexingConfiguration_managedFields :: Lens.Lens' ThingIndexingConfiguration (Prelude.Maybe [Field])
thingIndexingConfiguration_managedFields :: (Maybe [Field] -> f (Maybe [Field]))
-> ThingIndexingConfiguration -> f ThingIndexingConfiguration
thingIndexingConfiguration_managedFields = (ThingIndexingConfiguration -> Maybe [Field])
-> (ThingIndexingConfiguration
    -> Maybe [Field] -> ThingIndexingConfiguration)
-> Lens
     ThingIndexingConfiguration
     ThingIndexingConfiguration
     (Maybe [Field])
     (Maybe [Field])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingIndexingConfiguration' {Maybe [Field]
managedFields :: Maybe [Field]
$sel:managedFields:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe [Field]
managedFields} -> Maybe [Field]
managedFields) (\s :: ThingIndexingConfiguration
s@ThingIndexingConfiguration' {} Maybe [Field]
a -> ThingIndexingConfiguration
s {$sel:managedFields:ThingIndexingConfiguration' :: Maybe [Field]
managedFields = Maybe [Field]
a} :: ThingIndexingConfiguration) ((Maybe [Field] -> f (Maybe [Field]))
 -> ThingIndexingConfiguration -> f ThingIndexingConfiguration)
-> ((Maybe [Field] -> f (Maybe [Field]))
    -> Maybe [Field] -> f (Maybe [Field]))
-> (Maybe [Field] -> f (Maybe [Field]))
-> ThingIndexingConfiguration
-> f ThingIndexingConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Field] [Field] [Field] [Field]
-> Iso
     (Maybe [Field]) (Maybe [Field]) (Maybe [Field]) (Maybe [Field])
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 [Field] [Field] [Field] [Field]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Thing connectivity indexing mode. Valid values are:
--
-- -   STATUS – Your thing index contains connectivity status. To enable
--     thing connectivity indexing, /thingIndexMode/ must not be set to
--     OFF.
--
-- -   OFF - Thing connectivity status indexing is disabled.
thingIndexingConfiguration_thingConnectivityIndexingMode :: Lens.Lens' ThingIndexingConfiguration (Prelude.Maybe ThingConnectivityIndexingMode)
thingIndexingConfiguration_thingConnectivityIndexingMode :: (Maybe ThingConnectivityIndexingMode
 -> f (Maybe ThingConnectivityIndexingMode))
-> ThingIndexingConfiguration -> f ThingIndexingConfiguration
thingIndexingConfiguration_thingConnectivityIndexingMode = (ThingIndexingConfiguration -> Maybe ThingConnectivityIndexingMode)
-> (ThingIndexingConfiguration
    -> Maybe ThingConnectivityIndexingMode
    -> ThingIndexingConfiguration)
-> Lens
     ThingIndexingConfiguration
     ThingIndexingConfiguration
     (Maybe ThingConnectivityIndexingMode)
     (Maybe ThingConnectivityIndexingMode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingIndexingConfiguration' {Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode :: Maybe ThingConnectivityIndexingMode
$sel:thingConnectivityIndexingMode:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode} -> Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode) (\s :: ThingIndexingConfiguration
s@ThingIndexingConfiguration' {} Maybe ThingConnectivityIndexingMode
a -> ThingIndexingConfiguration
s {$sel:thingConnectivityIndexingMode:ThingIndexingConfiguration' :: Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode = Maybe ThingConnectivityIndexingMode
a} :: ThingIndexingConfiguration)

-- | Contains custom field names and their data type.
thingIndexingConfiguration_customFields :: Lens.Lens' ThingIndexingConfiguration (Prelude.Maybe [Field])
thingIndexingConfiguration_customFields :: (Maybe [Field] -> f (Maybe [Field]))
-> ThingIndexingConfiguration -> f ThingIndexingConfiguration
thingIndexingConfiguration_customFields = (ThingIndexingConfiguration -> Maybe [Field])
-> (ThingIndexingConfiguration
    -> Maybe [Field] -> ThingIndexingConfiguration)
-> Lens
     ThingIndexingConfiguration
     ThingIndexingConfiguration
     (Maybe [Field])
     (Maybe [Field])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingIndexingConfiguration' {Maybe [Field]
customFields :: Maybe [Field]
$sel:customFields:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe [Field]
customFields} -> Maybe [Field]
customFields) (\s :: ThingIndexingConfiguration
s@ThingIndexingConfiguration' {} Maybe [Field]
a -> ThingIndexingConfiguration
s {$sel:customFields:ThingIndexingConfiguration' :: Maybe [Field]
customFields = Maybe [Field]
a} :: ThingIndexingConfiguration) ((Maybe [Field] -> f (Maybe [Field]))
 -> ThingIndexingConfiguration -> f ThingIndexingConfiguration)
-> ((Maybe [Field] -> f (Maybe [Field]))
    -> Maybe [Field] -> f (Maybe [Field]))
-> (Maybe [Field] -> f (Maybe [Field]))
-> ThingIndexingConfiguration
-> f ThingIndexingConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Field] [Field] [Field] [Field]
-> Iso
     (Maybe [Field]) (Maybe [Field]) (Maybe [Field]) (Maybe [Field])
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 [Field] [Field] [Field] [Field]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Thing indexing mode. Valid values are:
--
-- -   REGISTRY – Your thing index contains registry data only.
--
-- -   REGISTRY_AND_SHADOW - Your thing index contains registry and shadow
--     data.
--
-- -   OFF - Thing indexing is disabled.
thingIndexingConfiguration_thingIndexingMode :: Lens.Lens' ThingIndexingConfiguration ThingIndexingMode
thingIndexingConfiguration_thingIndexingMode :: (ThingIndexingMode -> f ThingIndexingMode)
-> ThingIndexingConfiguration -> f ThingIndexingConfiguration
thingIndexingConfiguration_thingIndexingMode = (ThingIndexingConfiguration -> ThingIndexingMode)
-> (ThingIndexingConfiguration
    -> ThingIndexingMode -> ThingIndexingConfiguration)
-> Lens
     ThingIndexingConfiguration
     ThingIndexingConfiguration
     ThingIndexingMode
     ThingIndexingMode
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingIndexingConfiguration' {ThingIndexingMode
thingIndexingMode :: ThingIndexingMode
$sel:thingIndexingMode:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> ThingIndexingMode
thingIndexingMode} -> ThingIndexingMode
thingIndexingMode) (\s :: ThingIndexingConfiguration
s@ThingIndexingConfiguration' {} ThingIndexingMode
a -> ThingIndexingConfiguration
s {$sel:thingIndexingMode:ThingIndexingConfiguration' :: ThingIndexingMode
thingIndexingMode = ThingIndexingMode
a} :: ThingIndexingConfiguration)

instance Core.FromJSON ThingIndexingConfiguration where
  parseJSON :: Value -> Parser ThingIndexingConfiguration
parseJSON =
    String
-> (Object -> Parser ThingIndexingConfiguration)
-> Value
-> Parser ThingIndexingConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ThingIndexingConfiguration"
      ( \Object
x ->
          Maybe [Field]
-> Maybe ThingConnectivityIndexingMode
-> Maybe [Field]
-> ThingIndexingMode
-> ThingIndexingConfiguration
ThingIndexingConfiguration'
            (Maybe [Field]
 -> Maybe ThingConnectivityIndexingMode
 -> Maybe [Field]
 -> ThingIndexingMode
 -> ThingIndexingConfiguration)
-> Parser (Maybe [Field])
-> Parser
     (Maybe ThingConnectivityIndexingMode
      -> Maybe [Field]
      -> ThingIndexingMode
      -> ThingIndexingConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Field]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"managedFields" Parser (Maybe (Maybe [Field]))
-> Maybe [Field] -> Parser (Maybe [Field])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Field]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe ThingConnectivityIndexingMode
   -> Maybe [Field]
   -> ThingIndexingMode
   -> ThingIndexingConfiguration)
-> Parser (Maybe ThingConnectivityIndexingMode)
-> Parser
     (Maybe [Field] -> ThingIndexingMode -> ThingIndexingConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ThingConnectivityIndexingMode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"thingConnectivityIndexingMode")
            Parser
  (Maybe [Field] -> ThingIndexingMode -> ThingIndexingConfiguration)
-> Parser (Maybe [Field])
-> Parser (ThingIndexingMode -> ThingIndexingConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Field]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"customFields" Parser (Maybe (Maybe [Field]))
-> Maybe [Field] -> Parser (Maybe [Field])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Field]
forall a. Monoid a => a
Prelude.mempty)
            Parser (ThingIndexingMode -> ThingIndexingConfiguration)
-> Parser ThingIndexingMode -> Parser ThingIndexingConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ThingIndexingMode
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"thingIndexingMode")
      )

instance Prelude.Hashable ThingIndexingConfiguration

instance Prelude.NFData ThingIndexingConfiguration

instance Core.ToJSON ThingIndexingConfiguration where
  toJSON :: ThingIndexingConfiguration -> Value
toJSON ThingIndexingConfiguration' {Maybe [Field]
Maybe ThingConnectivityIndexingMode
ThingIndexingMode
thingIndexingMode :: ThingIndexingMode
customFields :: Maybe [Field]
thingConnectivityIndexingMode :: Maybe ThingConnectivityIndexingMode
managedFields :: Maybe [Field]
$sel:thingIndexingMode:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> ThingIndexingMode
$sel:customFields:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe [Field]
$sel:thingConnectivityIndexingMode:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe ThingConnectivityIndexingMode
$sel:managedFields:ThingIndexingConfiguration' :: ThingIndexingConfiguration -> Maybe [Field]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"managedFields" Text -> [Field] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Field] -> Pair) -> Maybe [Field] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Field]
managedFields,
            (Text
"thingConnectivityIndexingMode" Text -> ThingConnectivityIndexingMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ThingConnectivityIndexingMode -> Pair)
-> Maybe ThingConnectivityIndexingMode -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ThingConnectivityIndexingMode
thingConnectivityIndexingMode,
            (Text
"customFields" Text -> [Field] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Field] -> Pair) -> Maybe [Field] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Field]
customFields,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"thingIndexingMode" Text -> ThingIndexingMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ThingIndexingMode
thingIndexingMode)
          ]
      )