{-# 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.IoTAnalytics.Types.DatastorePartition
-- 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.IoTAnalytics.Types.DatastorePartition where

import qualified Amazonka.Core as Core
import Amazonka.IoTAnalytics.Types.Partition
import Amazonka.IoTAnalytics.Types.TimestampPartition
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A single dimension to partition a data store. The dimension must be an
-- @AttributePartition@ or a @TimestampPartition@.
--
-- /See:/ 'newDatastorePartition' smart constructor.
data DatastorePartition = DatastorePartition'
  { -- | A partition dimension defined by an @attributeName@.
    DatastorePartition -> Maybe Partition
attributePartition :: Prelude.Maybe Partition,
    -- | A partition dimension defined by a timestamp attribute.
    DatastorePartition -> Maybe TimestampPartition
timestampPartition :: Prelude.Maybe TimestampPartition
  }
  deriving (DatastorePartition -> DatastorePartition -> Bool
(DatastorePartition -> DatastorePartition -> Bool)
-> (DatastorePartition -> DatastorePartition -> Bool)
-> Eq DatastorePartition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DatastorePartition -> DatastorePartition -> Bool
$c/= :: DatastorePartition -> DatastorePartition -> Bool
== :: DatastorePartition -> DatastorePartition -> Bool
$c== :: DatastorePartition -> DatastorePartition -> Bool
Prelude.Eq, ReadPrec [DatastorePartition]
ReadPrec DatastorePartition
Int -> ReadS DatastorePartition
ReadS [DatastorePartition]
(Int -> ReadS DatastorePartition)
-> ReadS [DatastorePartition]
-> ReadPrec DatastorePartition
-> ReadPrec [DatastorePartition]
-> Read DatastorePartition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DatastorePartition]
$creadListPrec :: ReadPrec [DatastorePartition]
readPrec :: ReadPrec DatastorePartition
$creadPrec :: ReadPrec DatastorePartition
readList :: ReadS [DatastorePartition]
$creadList :: ReadS [DatastorePartition]
readsPrec :: Int -> ReadS DatastorePartition
$creadsPrec :: Int -> ReadS DatastorePartition
Prelude.Read, Int -> DatastorePartition -> ShowS
[DatastorePartition] -> ShowS
DatastorePartition -> String
(Int -> DatastorePartition -> ShowS)
-> (DatastorePartition -> String)
-> ([DatastorePartition] -> ShowS)
-> Show DatastorePartition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DatastorePartition] -> ShowS
$cshowList :: [DatastorePartition] -> ShowS
show :: DatastorePartition -> String
$cshow :: DatastorePartition -> String
showsPrec :: Int -> DatastorePartition -> ShowS
$cshowsPrec :: Int -> DatastorePartition -> ShowS
Prelude.Show, (forall x. DatastorePartition -> Rep DatastorePartition x)
-> (forall x. Rep DatastorePartition x -> DatastorePartition)
-> Generic DatastorePartition
forall x. Rep DatastorePartition x -> DatastorePartition
forall x. DatastorePartition -> Rep DatastorePartition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DatastorePartition x -> DatastorePartition
$cfrom :: forall x. DatastorePartition -> Rep DatastorePartition x
Prelude.Generic)

-- |
-- Create a value of 'DatastorePartition' 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:
--
-- 'attributePartition', 'datastorePartition_attributePartition' - A partition dimension defined by an @attributeName@.
--
-- 'timestampPartition', 'datastorePartition_timestampPartition' - A partition dimension defined by a timestamp attribute.
newDatastorePartition ::
  DatastorePartition
newDatastorePartition :: DatastorePartition
newDatastorePartition =
  DatastorePartition' :: Maybe Partition -> Maybe TimestampPartition -> DatastorePartition
DatastorePartition'
    { $sel:attributePartition:DatastorePartition' :: Maybe Partition
attributePartition =
        Maybe Partition
forall a. Maybe a
Prelude.Nothing,
      $sel:timestampPartition:DatastorePartition' :: Maybe TimestampPartition
timestampPartition = Maybe TimestampPartition
forall a. Maybe a
Prelude.Nothing
    }

-- | A partition dimension defined by an @attributeName@.
datastorePartition_attributePartition :: Lens.Lens' DatastorePartition (Prelude.Maybe Partition)
datastorePartition_attributePartition :: (Maybe Partition -> f (Maybe Partition))
-> DatastorePartition -> f DatastorePartition
datastorePartition_attributePartition = (DatastorePartition -> Maybe Partition)
-> (DatastorePartition -> Maybe Partition -> DatastorePartition)
-> Lens
     DatastorePartition
     DatastorePartition
     (Maybe Partition)
     (Maybe Partition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatastorePartition' {Maybe Partition
attributePartition :: Maybe Partition
$sel:attributePartition:DatastorePartition' :: DatastorePartition -> Maybe Partition
attributePartition} -> Maybe Partition
attributePartition) (\s :: DatastorePartition
s@DatastorePartition' {} Maybe Partition
a -> DatastorePartition
s {$sel:attributePartition:DatastorePartition' :: Maybe Partition
attributePartition = Maybe Partition
a} :: DatastorePartition)

-- | A partition dimension defined by a timestamp attribute.
datastorePartition_timestampPartition :: Lens.Lens' DatastorePartition (Prelude.Maybe TimestampPartition)
datastorePartition_timestampPartition :: (Maybe TimestampPartition -> f (Maybe TimestampPartition))
-> DatastorePartition -> f DatastorePartition
datastorePartition_timestampPartition = (DatastorePartition -> Maybe TimestampPartition)
-> (DatastorePartition
    -> Maybe TimestampPartition -> DatastorePartition)
-> Lens
     DatastorePartition
     DatastorePartition
     (Maybe TimestampPartition)
     (Maybe TimestampPartition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DatastorePartition' {Maybe TimestampPartition
timestampPartition :: Maybe TimestampPartition
$sel:timestampPartition:DatastorePartition' :: DatastorePartition -> Maybe TimestampPartition
timestampPartition} -> Maybe TimestampPartition
timestampPartition) (\s :: DatastorePartition
s@DatastorePartition' {} Maybe TimestampPartition
a -> DatastorePartition
s {$sel:timestampPartition:DatastorePartition' :: Maybe TimestampPartition
timestampPartition = Maybe TimestampPartition
a} :: DatastorePartition)

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

instance Prelude.Hashable DatastorePartition

instance Prelude.NFData DatastorePartition

instance Core.ToJSON DatastorePartition where
  toJSON :: DatastorePartition -> Value
toJSON DatastorePartition' {Maybe Partition
Maybe TimestampPartition
timestampPartition :: Maybe TimestampPartition
attributePartition :: Maybe Partition
$sel:timestampPartition:DatastorePartition' :: DatastorePartition -> Maybe TimestampPartition
$sel:attributePartition:DatastorePartition' :: DatastorePartition -> Maybe Partition
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"attributePartition" Text -> Partition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Partition -> Pair) -> Maybe Partition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Partition
attributePartition,
            (Text
"timestampPartition" Text -> TimestampPartition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TimestampPartition -> Pair)
-> Maybe TimestampPartition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TimestampPartition
timestampPartition
          ]
      )