{-# 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.ThingGroupIndexingConfiguration
-- 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.ThingGroupIndexingConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.Field
import Amazonka.IoT.Types.ThingGroupIndexingMode
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Thing group indexing configuration.
--
-- /See:/ 'newThingGroupIndexingConfiguration' smart constructor.
data ThingGroupIndexingConfiguration = ThingGroupIndexingConfiguration'
  { -- | Contains fields that are indexed and whose types are already known by
    -- the Fleet Indexing service.
    ThingGroupIndexingConfiguration -> Maybe [Field]
managedFields :: Prelude.Maybe [Field],
    -- | A list of thing group fields to index. This list cannot contain any
    -- managed fields. Use the GetIndexingConfiguration API to get a list of
    -- managed fields.
    --
    -- Contains custom field names and their data type.
    ThingGroupIndexingConfiguration -> Maybe [Field]
customFields :: Prelude.Maybe [Field],
    -- | Thing group indexing mode.
    ThingGroupIndexingConfiguration -> ThingGroupIndexingMode
thingGroupIndexingMode :: ThingGroupIndexingMode
  }
  deriving (ThingGroupIndexingConfiguration
-> ThingGroupIndexingConfiguration -> Bool
(ThingGroupIndexingConfiguration
 -> ThingGroupIndexingConfiguration -> Bool)
-> (ThingGroupIndexingConfiguration
    -> ThingGroupIndexingConfiguration -> Bool)
-> Eq ThingGroupIndexingConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ThingGroupIndexingConfiguration
-> ThingGroupIndexingConfiguration -> Bool
$c/= :: ThingGroupIndexingConfiguration
-> ThingGroupIndexingConfiguration -> Bool
== :: ThingGroupIndexingConfiguration
-> ThingGroupIndexingConfiguration -> Bool
$c== :: ThingGroupIndexingConfiguration
-> ThingGroupIndexingConfiguration -> Bool
Prelude.Eq, ReadPrec [ThingGroupIndexingConfiguration]
ReadPrec ThingGroupIndexingConfiguration
Int -> ReadS ThingGroupIndexingConfiguration
ReadS [ThingGroupIndexingConfiguration]
(Int -> ReadS ThingGroupIndexingConfiguration)
-> ReadS [ThingGroupIndexingConfiguration]
-> ReadPrec ThingGroupIndexingConfiguration
-> ReadPrec [ThingGroupIndexingConfiguration]
-> Read ThingGroupIndexingConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ThingGroupIndexingConfiguration]
$creadListPrec :: ReadPrec [ThingGroupIndexingConfiguration]
readPrec :: ReadPrec ThingGroupIndexingConfiguration
$creadPrec :: ReadPrec ThingGroupIndexingConfiguration
readList :: ReadS [ThingGroupIndexingConfiguration]
$creadList :: ReadS [ThingGroupIndexingConfiguration]
readsPrec :: Int -> ReadS ThingGroupIndexingConfiguration
$creadsPrec :: Int -> ReadS ThingGroupIndexingConfiguration
Prelude.Read, Int -> ThingGroupIndexingConfiguration -> ShowS
[ThingGroupIndexingConfiguration] -> ShowS
ThingGroupIndexingConfiguration -> String
(Int -> ThingGroupIndexingConfiguration -> ShowS)
-> (ThingGroupIndexingConfiguration -> String)
-> ([ThingGroupIndexingConfiguration] -> ShowS)
-> Show ThingGroupIndexingConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ThingGroupIndexingConfiguration] -> ShowS
$cshowList :: [ThingGroupIndexingConfiguration] -> ShowS
show :: ThingGroupIndexingConfiguration -> String
$cshow :: ThingGroupIndexingConfiguration -> String
showsPrec :: Int -> ThingGroupIndexingConfiguration -> ShowS
$cshowsPrec :: Int -> ThingGroupIndexingConfiguration -> ShowS
Prelude.Show, (forall x.
 ThingGroupIndexingConfiguration
 -> Rep ThingGroupIndexingConfiguration x)
-> (forall x.
    Rep ThingGroupIndexingConfiguration x
    -> ThingGroupIndexingConfiguration)
-> Generic ThingGroupIndexingConfiguration
forall x.
Rep ThingGroupIndexingConfiguration x
-> ThingGroupIndexingConfiguration
forall x.
ThingGroupIndexingConfiguration
-> Rep ThingGroupIndexingConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ThingGroupIndexingConfiguration x
-> ThingGroupIndexingConfiguration
$cfrom :: forall x.
ThingGroupIndexingConfiguration
-> Rep ThingGroupIndexingConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ThingGroupIndexingConfiguration' 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', 'thingGroupIndexingConfiguration_managedFields' - Contains fields that are indexed and whose types are already known by
-- the Fleet Indexing service.
--
-- 'customFields', 'thingGroupIndexingConfiguration_customFields' - A list of thing group fields to index. This list cannot contain any
-- managed fields. Use the GetIndexingConfiguration API to get a list of
-- managed fields.
--
-- Contains custom field names and their data type.
--
-- 'thingGroupIndexingMode', 'thingGroupIndexingConfiguration_thingGroupIndexingMode' - Thing group indexing mode.
newThingGroupIndexingConfiguration ::
  -- | 'thingGroupIndexingMode'
  ThingGroupIndexingMode ->
  ThingGroupIndexingConfiguration
newThingGroupIndexingConfiguration :: ThingGroupIndexingMode -> ThingGroupIndexingConfiguration
newThingGroupIndexingConfiguration
  ThingGroupIndexingMode
pThingGroupIndexingMode_ =
    ThingGroupIndexingConfiguration' :: Maybe [Field]
-> Maybe [Field]
-> ThingGroupIndexingMode
-> ThingGroupIndexingConfiguration
ThingGroupIndexingConfiguration'
      { $sel:managedFields:ThingGroupIndexingConfiguration' :: Maybe [Field]
managedFields =
          Maybe [Field]
forall a. Maybe a
Prelude.Nothing,
        $sel:customFields:ThingGroupIndexingConfiguration' :: Maybe [Field]
customFields = Maybe [Field]
forall a. Maybe a
Prelude.Nothing,
        $sel:thingGroupIndexingMode:ThingGroupIndexingConfiguration' :: ThingGroupIndexingMode
thingGroupIndexingMode =
          ThingGroupIndexingMode
pThingGroupIndexingMode_
      }

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

-- | A list of thing group fields to index. This list cannot contain any
-- managed fields. Use the GetIndexingConfiguration API to get a list of
-- managed fields.
--
-- Contains custom field names and their data type.
thingGroupIndexingConfiguration_customFields :: Lens.Lens' ThingGroupIndexingConfiguration (Prelude.Maybe [Field])
thingGroupIndexingConfiguration_customFields :: (Maybe [Field] -> f (Maybe [Field]))
-> ThingGroupIndexingConfiguration
-> f ThingGroupIndexingConfiguration
thingGroupIndexingConfiguration_customFields = (ThingGroupIndexingConfiguration -> Maybe [Field])
-> (ThingGroupIndexingConfiguration
    -> Maybe [Field] -> ThingGroupIndexingConfiguration)
-> Lens
     ThingGroupIndexingConfiguration
     ThingGroupIndexingConfiguration
     (Maybe [Field])
     (Maybe [Field])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingGroupIndexingConfiguration' {Maybe [Field]
customFields :: Maybe [Field]
$sel:customFields:ThingGroupIndexingConfiguration' :: ThingGroupIndexingConfiguration -> Maybe [Field]
customFields} -> Maybe [Field]
customFields) (\s :: ThingGroupIndexingConfiguration
s@ThingGroupIndexingConfiguration' {} Maybe [Field]
a -> ThingGroupIndexingConfiguration
s {$sel:customFields:ThingGroupIndexingConfiguration' :: Maybe [Field]
customFields = Maybe [Field]
a} :: ThingGroupIndexingConfiguration) ((Maybe [Field] -> f (Maybe [Field]))
 -> ThingGroupIndexingConfiguration
 -> f ThingGroupIndexingConfiguration)
-> ((Maybe [Field] -> f (Maybe [Field]))
    -> Maybe [Field] -> f (Maybe [Field]))
-> (Maybe [Field] -> f (Maybe [Field]))
-> ThingGroupIndexingConfiguration
-> f ThingGroupIndexingConfiguration
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 group indexing mode.
thingGroupIndexingConfiguration_thingGroupIndexingMode :: Lens.Lens' ThingGroupIndexingConfiguration ThingGroupIndexingMode
thingGroupIndexingConfiguration_thingGroupIndexingMode :: (ThingGroupIndexingMode -> f ThingGroupIndexingMode)
-> ThingGroupIndexingConfiguration
-> f ThingGroupIndexingConfiguration
thingGroupIndexingConfiguration_thingGroupIndexingMode = (ThingGroupIndexingConfiguration -> ThingGroupIndexingMode)
-> (ThingGroupIndexingConfiguration
    -> ThingGroupIndexingMode -> ThingGroupIndexingConfiguration)
-> Lens
     ThingGroupIndexingConfiguration
     ThingGroupIndexingConfiguration
     ThingGroupIndexingMode
     ThingGroupIndexingMode
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ThingGroupIndexingConfiguration' {ThingGroupIndexingMode
thingGroupIndexingMode :: ThingGroupIndexingMode
$sel:thingGroupIndexingMode:ThingGroupIndexingConfiguration' :: ThingGroupIndexingConfiguration -> ThingGroupIndexingMode
thingGroupIndexingMode} -> ThingGroupIndexingMode
thingGroupIndexingMode) (\s :: ThingGroupIndexingConfiguration
s@ThingGroupIndexingConfiguration' {} ThingGroupIndexingMode
a -> ThingGroupIndexingConfiguration
s {$sel:thingGroupIndexingMode:ThingGroupIndexingConfiguration' :: ThingGroupIndexingMode
thingGroupIndexingMode = ThingGroupIndexingMode
a} :: ThingGroupIndexingConfiguration)

instance
  Core.FromJSON
    ThingGroupIndexingConfiguration
  where
  parseJSON :: Value -> Parser ThingGroupIndexingConfiguration
parseJSON =
    String
-> (Object -> Parser ThingGroupIndexingConfiguration)
-> Value
-> Parser ThingGroupIndexingConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ThingGroupIndexingConfiguration"
      ( \Object
x ->
          Maybe [Field]
-> Maybe [Field]
-> ThingGroupIndexingMode
-> ThingGroupIndexingConfiguration
ThingGroupIndexingConfiguration'
            (Maybe [Field]
 -> Maybe [Field]
 -> ThingGroupIndexingMode
 -> ThingGroupIndexingConfiguration)
-> Parser (Maybe [Field])
-> Parser
     (Maybe [Field]
      -> ThingGroupIndexingMode -> ThingGroupIndexingConfiguration)
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 [Field]
   -> ThingGroupIndexingMode -> ThingGroupIndexingConfiguration)
-> Parser (Maybe [Field])
-> Parser
     (ThingGroupIndexingMode -> ThingGroupIndexingConfiguration)
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 (ThingGroupIndexingMode -> ThingGroupIndexingConfiguration)
-> Parser ThingGroupIndexingMode
-> Parser ThingGroupIndexingConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ThingGroupIndexingMode
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"thingGroupIndexingMode")
      )

instance
  Prelude.Hashable
    ThingGroupIndexingConfiguration

instance
  Prelude.NFData
    ThingGroupIndexingConfiguration

instance Core.ToJSON ThingGroupIndexingConfiguration where
  toJSON :: ThingGroupIndexingConfiguration -> Value
toJSON ThingGroupIndexingConfiguration' {Maybe [Field]
ThingGroupIndexingMode
thingGroupIndexingMode :: ThingGroupIndexingMode
customFields :: Maybe [Field]
managedFields :: Maybe [Field]
$sel:thingGroupIndexingMode:ThingGroupIndexingConfiguration' :: ThingGroupIndexingConfiguration -> ThingGroupIndexingMode
$sel:customFields:ThingGroupIndexingConfiguration' :: ThingGroupIndexingConfiguration -> Maybe [Field]
$sel:managedFields:ThingGroupIndexingConfiguration' :: ThingGroupIndexingConfiguration -> 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
"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
"thingGroupIndexingMode"
                  Text -> ThingGroupIndexingMode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ThingGroupIndexingMode
thingGroupIndexingMode
              )
          ]
      )