{-# 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.DataBrew.Types.Sample
-- 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.DataBrew.Types.Sample where

import qualified Amazonka.Core as Core
import Amazonka.DataBrew.Types.SampleType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents the sample size and sampling type for DataBrew to use for
-- interactive data analysis.
--
-- /See:/ 'newSample' smart constructor.
data Sample = Sample'
  { -- | The number of rows in the sample.
    Sample -> Maybe Natural
size :: Prelude.Maybe Prelude.Natural,
    -- | The way in which DataBrew obtains rows from a dataset.
    Sample -> SampleType
type' :: SampleType
  }
  deriving (Sample -> Sample -> Bool
(Sample -> Sample -> Bool)
-> (Sample -> Sample -> Bool) -> Eq Sample
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Sample -> Sample -> Bool
$c/= :: Sample -> Sample -> Bool
== :: Sample -> Sample -> Bool
$c== :: Sample -> Sample -> Bool
Prelude.Eq, ReadPrec [Sample]
ReadPrec Sample
Int -> ReadS Sample
ReadS [Sample]
(Int -> ReadS Sample)
-> ReadS [Sample]
-> ReadPrec Sample
-> ReadPrec [Sample]
-> Read Sample
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Sample]
$creadListPrec :: ReadPrec [Sample]
readPrec :: ReadPrec Sample
$creadPrec :: ReadPrec Sample
readList :: ReadS [Sample]
$creadList :: ReadS [Sample]
readsPrec :: Int -> ReadS Sample
$creadsPrec :: Int -> ReadS Sample
Prelude.Read, Int -> Sample -> ShowS
[Sample] -> ShowS
Sample -> String
(Int -> Sample -> ShowS)
-> (Sample -> String) -> ([Sample] -> ShowS) -> Show Sample
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Sample] -> ShowS
$cshowList :: [Sample] -> ShowS
show :: Sample -> String
$cshow :: Sample -> String
showsPrec :: Int -> Sample -> ShowS
$cshowsPrec :: Int -> Sample -> ShowS
Prelude.Show, (forall x. Sample -> Rep Sample x)
-> (forall x. Rep Sample x -> Sample) -> Generic Sample
forall x. Rep Sample x -> Sample
forall x. Sample -> Rep Sample x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Sample x -> Sample
$cfrom :: forall x. Sample -> Rep Sample x
Prelude.Generic)

-- |
-- Create a value of 'Sample' 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:
--
-- 'size', 'sample_size' - The number of rows in the sample.
--
-- 'type'', 'sample_type' - The way in which DataBrew obtains rows from a dataset.
newSample ::
  -- | 'type''
  SampleType ->
  Sample
newSample :: SampleType -> Sample
newSample SampleType
pType_ =
  Sample' :: Maybe Natural -> SampleType -> Sample
Sample' {$sel:size:Sample' :: Maybe Natural
size = Maybe Natural
forall a. Maybe a
Prelude.Nothing, $sel:type':Sample' :: SampleType
type' = SampleType
pType_}

-- | The number of rows in the sample.
sample_size :: Lens.Lens' Sample (Prelude.Maybe Prelude.Natural)
sample_size :: (Maybe Natural -> f (Maybe Natural)) -> Sample -> f Sample
sample_size = (Sample -> Maybe Natural)
-> (Sample -> Maybe Natural -> Sample)
-> Lens Sample Sample (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sample' {Maybe Natural
size :: Maybe Natural
$sel:size:Sample' :: Sample -> Maybe Natural
size} -> Maybe Natural
size) (\s :: Sample
s@Sample' {} Maybe Natural
a -> Sample
s {$sel:size:Sample' :: Maybe Natural
size = Maybe Natural
a} :: Sample)

-- | The way in which DataBrew obtains rows from a dataset.
sample_type :: Lens.Lens' Sample SampleType
sample_type :: (SampleType -> f SampleType) -> Sample -> f Sample
sample_type = (Sample -> SampleType)
-> (Sample -> SampleType -> Sample)
-> Lens Sample Sample SampleType SampleType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sample' {SampleType
type' :: SampleType
$sel:type':Sample' :: Sample -> SampleType
type'} -> SampleType
type') (\s :: Sample
s@Sample' {} SampleType
a -> Sample
s {$sel:type':Sample' :: SampleType
type' = SampleType
a} :: Sample)

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

instance Prelude.Hashable Sample

instance Prelude.NFData Sample

instance Core.ToJSON Sample where
  toJSON :: Sample -> Value
toJSON Sample' {Maybe Natural
SampleType
type' :: SampleType
size :: Maybe Natural
$sel:type':Sample' :: Sample -> SampleType
$sel:size:Sample' :: Sample -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Size" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
size,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> SampleType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SampleType
type')
          ]
      )