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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A partition dimension defined by a timestamp attribute.
--
-- /See:/ 'newTimestampPartition' smart constructor.
data TimestampPartition = TimestampPartition'
  { -- | The timestamp format of a partition defined by a timestamp. The default
    -- format is seconds since epoch (January 1, 1970 at midnight UTC time).
    TimestampPartition -> Maybe Text
timestampFormat :: Prelude.Maybe Prelude.Text,
    -- | The attribute name of the partition defined by a timestamp.
    TimestampPartition -> Text
attributeName :: Prelude.Text
  }
  deriving (TimestampPartition -> TimestampPartition -> Bool
(TimestampPartition -> TimestampPartition -> Bool)
-> (TimestampPartition -> TimestampPartition -> Bool)
-> Eq TimestampPartition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimestampPartition -> TimestampPartition -> Bool
$c/= :: TimestampPartition -> TimestampPartition -> Bool
== :: TimestampPartition -> TimestampPartition -> Bool
$c== :: TimestampPartition -> TimestampPartition -> Bool
Prelude.Eq, ReadPrec [TimestampPartition]
ReadPrec TimestampPartition
Int -> ReadS TimestampPartition
ReadS [TimestampPartition]
(Int -> ReadS TimestampPartition)
-> ReadS [TimestampPartition]
-> ReadPrec TimestampPartition
-> ReadPrec [TimestampPartition]
-> Read TimestampPartition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimestampPartition]
$creadListPrec :: ReadPrec [TimestampPartition]
readPrec :: ReadPrec TimestampPartition
$creadPrec :: ReadPrec TimestampPartition
readList :: ReadS [TimestampPartition]
$creadList :: ReadS [TimestampPartition]
readsPrec :: Int -> ReadS TimestampPartition
$creadsPrec :: Int -> ReadS TimestampPartition
Prelude.Read, Int -> TimestampPartition -> ShowS
[TimestampPartition] -> ShowS
TimestampPartition -> String
(Int -> TimestampPartition -> ShowS)
-> (TimestampPartition -> String)
-> ([TimestampPartition] -> ShowS)
-> Show TimestampPartition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimestampPartition] -> ShowS
$cshowList :: [TimestampPartition] -> ShowS
show :: TimestampPartition -> String
$cshow :: TimestampPartition -> String
showsPrec :: Int -> TimestampPartition -> ShowS
$cshowsPrec :: Int -> TimestampPartition -> ShowS
Prelude.Show, (forall x. TimestampPartition -> Rep TimestampPartition x)
-> (forall x. Rep TimestampPartition x -> TimestampPartition)
-> Generic TimestampPartition
forall x. Rep TimestampPartition x -> TimestampPartition
forall x. TimestampPartition -> Rep TimestampPartition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimestampPartition x -> TimestampPartition
$cfrom :: forall x. TimestampPartition -> Rep TimestampPartition x
Prelude.Generic)

-- |
-- Create a value of 'TimestampPartition' 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:
--
-- 'timestampFormat', 'timestampPartition_timestampFormat' - The timestamp format of a partition defined by a timestamp. The default
-- format is seconds since epoch (January 1, 1970 at midnight UTC time).
--
-- 'attributeName', 'timestampPartition_attributeName' - The attribute name of the partition defined by a timestamp.
newTimestampPartition ::
  -- | 'attributeName'
  Prelude.Text ->
  TimestampPartition
newTimestampPartition :: Text -> TimestampPartition
newTimestampPartition Text
pAttributeName_ =
  TimestampPartition' :: Maybe Text -> Text -> TimestampPartition
TimestampPartition'
    { $sel:timestampFormat:TimestampPartition' :: Maybe Text
timestampFormat =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:attributeName:TimestampPartition' :: Text
attributeName = Text
pAttributeName_
    }

-- | The timestamp format of a partition defined by a timestamp. The default
-- format is seconds since epoch (January 1, 1970 at midnight UTC time).
timestampPartition_timestampFormat :: Lens.Lens' TimestampPartition (Prelude.Maybe Prelude.Text)
timestampPartition_timestampFormat :: (Maybe Text -> f (Maybe Text))
-> TimestampPartition -> f TimestampPartition
timestampPartition_timestampFormat = (TimestampPartition -> Maybe Text)
-> (TimestampPartition -> Maybe Text -> TimestampPartition)
-> Lens
     TimestampPartition TimestampPartition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestampPartition' {Maybe Text
timestampFormat :: Maybe Text
$sel:timestampFormat:TimestampPartition' :: TimestampPartition -> Maybe Text
timestampFormat} -> Maybe Text
timestampFormat) (\s :: TimestampPartition
s@TimestampPartition' {} Maybe Text
a -> TimestampPartition
s {$sel:timestampFormat:TimestampPartition' :: Maybe Text
timestampFormat = Maybe Text
a} :: TimestampPartition)

-- | The attribute name of the partition defined by a timestamp.
timestampPartition_attributeName :: Lens.Lens' TimestampPartition Prelude.Text
timestampPartition_attributeName :: (Text -> f Text) -> TimestampPartition -> f TimestampPartition
timestampPartition_attributeName = (TimestampPartition -> Text)
-> (TimestampPartition -> Text -> TimestampPartition)
-> Lens TimestampPartition TimestampPartition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestampPartition' {Text
attributeName :: Text
$sel:attributeName:TimestampPartition' :: TimestampPartition -> Text
attributeName} -> Text
attributeName) (\s :: TimestampPartition
s@TimestampPartition' {} Text
a -> TimestampPartition
s {$sel:attributeName:TimestampPartition' :: Text
attributeName = Text
a} :: TimestampPartition)

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

instance Prelude.Hashable TimestampPartition

instance Prelude.NFData TimestampPartition

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