{-# 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.SecurityHub.Types.DateRange
-- 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.SecurityHub.Types.DateRange where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SecurityHub.Types.DateRangeUnit

-- | A date range for the date filter.
--
-- /See:/ 'newDateRange' smart constructor.
data DateRange = DateRange'
  { -- | A date range value for the date filter.
    DateRange -> Maybe Int
value :: Prelude.Maybe Prelude.Int,
    -- | A date range unit for the date filter.
    DateRange -> Maybe DateRangeUnit
unit :: Prelude.Maybe DateRangeUnit
  }
  deriving (DateRange -> DateRange -> Bool
(DateRange -> DateRange -> Bool)
-> (DateRange -> DateRange -> Bool) -> Eq DateRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateRange -> DateRange -> Bool
$c/= :: DateRange -> DateRange -> Bool
== :: DateRange -> DateRange -> Bool
$c== :: DateRange -> DateRange -> Bool
Prelude.Eq, ReadPrec [DateRange]
ReadPrec DateRange
Int -> ReadS DateRange
ReadS [DateRange]
(Int -> ReadS DateRange)
-> ReadS [DateRange]
-> ReadPrec DateRange
-> ReadPrec [DateRange]
-> Read DateRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DateRange]
$creadListPrec :: ReadPrec [DateRange]
readPrec :: ReadPrec DateRange
$creadPrec :: ReadPrec DateRange
readList :: ReadS [DateRange]
$creadList :: ReadS [DateRange]
readsPrec :: Int -> ReadS DateRange
$creadsPrec :: Int -> ReadS DateRange
Prelude.Read, Int -> DateRange -> ShowS
[DateRange] -> ShowS
DateRange -> String
(Int -> DateRange -> ShowS)
-> (DateRange -> String)
-> ([DateRange] -> ShowS)
-> Show DateRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateRange] -> ShowS
$cshowList :: [DateRange] -> ShowS
show :: DateRange -> String
$cshow :: DateRange -> String
showsPrec :: Int -> DateRange -> ShowS
$cshowsPrec :: Int -> DateRange -> ShowS
Prelude.Show, (forall x. DateRange -> Rep DateRange x)
-> (forall x. Rep DateRange x -> DateRange) -> Generic DateRange
forall x. Rep DateRange x -> DateRange
forall x. DateRange -> Rep DateRange x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DateRange x -> DateRange
$cfrom :: forall x. DateRange -> Rep DateRange x
Prelude.Generic)

-- |
-- Create a value of 'DateRange' 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:
--
-- 'value', 'dateRange_value' - A date range value for the date filter.
--
-- 'unit', 'dateRange_unit' - A date range unit for the date filter.
newDateRange ::
  DateRange
newDateRange :: DateRange
newDateRange =
  DateRange' :: Maybe Int -> Maybe DateRangeUnit -> DateRange
DateRange'
    { $sel:value:DateRange' :: Maybe Int
value = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:unit:DateRange' :: Maybe DateRangeUnit
unit = Maybe DateRangeUnit
forall a. Maybe a
Prelude.Nothing
    }

-- | A date range value for the date filter.
dateRange_value :: Lens.Lens' DateRange (Prelude.Maybe Prelude.Int)
dateRange_value :: (Maybe Int -> f (Maybe Int)) -> DateRange -> f DateRange
dateRange_value = (DateRange -> Maybe Int)
-> (DateRange -> Maybe Int -> DateRange)
-> Lens DateRange DateRange (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateRange' {Maybe Int
value :: Maybe Int
$sel:value:DateRange' :: DateRange -> Maybe Int
value} -> Maybe Int
value) (\s :: DateRange
s@DateRange' {} Maybe Int
a -> DateRange
s {$sel:value:DateRange' :: Maybe Int
value = Maybe Int
a} :: DateRange)

-- | A date range unit for the date filter.
dateRange_unit :: Lens.Lens' DateRange (Prelude.Maybe DateRangeUnit)
dateRange_unit :: (Maybe DateRangeUnit -> f (Maybe DateRangeUnit))
-> DateRange -> f DateRange
dateRange_unit = (DateRange -> Maybe DateRangeUnit)
-> (DateRange -> Maybe DateRangeUnit -> DateRange)
-> Lens
     DateRange DateRange (Maybe DateRangeUnit) (Maybe DateRangeUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DateRange' {Maybe DateRangeUnit
unit :: Maybe DateRangeUnit
$sel:unit:DateRange' :: DateRange -> Maybe DateRangeUnit
unit} -> Maybe DateRangeUnit
unit) (\s :: DateRange
s@DateRange' {} Maybe DateRangeUnit
a -> DateRange
s {$sel:unit:DateRange' :: Maybe DateRangeUnit
unit = Maybe DateRangeUnit
a} :: DateRange)

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

instance Prelude.Hashable DateRange

instance Prelude.NFData DateRange

instance Core.ToJSON DateRange where
  toJSON :: DateRange -> Value
toJSON DateRange' {Maybe Int
Maybe DateRangeUnit
unit :: Maybe DateRangeUnit
value :: Maybe Int
$sel:unit:DateRange' :: DateRange -> Maybe DateRangeUnit
$sel:value:DateRange' :: DateRange -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Value" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
value,
            (Text
"Unit" Text -> DateRangeUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DateRangeUnit -> Pair) -> Maybe DateRangeUnit -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DateRangeUnit
unit
          ]
      )