{-# 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.LookoutMetrics.Types.FileFormatDescriptor
-- 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.LookoutMetrics.Types.FileFormatDescriptor where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LookoutMetrics.Types.CsvFormatDescriptor
import Amazonka.LookoutMetrics.Types.JsonFormatDescriptor
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a source file\'s formatting.
--
-- /See:/ 'newFileFormatDescriptor' smart constructor.
data FileFormatDescriptor = FileFormatDescriptor'
  { -- | Contains information about how a source JSON data file should be
    -- analyzed.
    FileFormatDescriptor -> Maybe JsonFormatDescriptor
jsonFormatDescriptor :: Prelude.Maybe JsonFormatDescriptor,
    -- | Contains information about how a source CSV data file should be
    -- analyzed.
    FileFormatDescriptor -> Maybe CsvFormatDescriptor
csvFormatDescriptor :: Prelude.Maybe CsvFormatDescriptor
  }
  deriving (FileFormatDescriptor -> FileFormatDescriptor -> Bool
(FileFormatDescriptor -> FileFormatDescriptor -> Bool)
-> (FileFormatDescriptor -> FileFormatDescriptor -> Bool)
-> Eq FileFormatDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileFormatDescriptor -> FileFormatDescriptor -> Bool
$c/= :: FileFormatDescriptor -> FileFormatDescriptor -> Bool
== :: FileFormatDescriptor -> FileFormatDescriptor -> Bool
$c== :: FileFormatDescriptor -> FileFormatDescriptor -> Bool
Prelude.Eq, ReadPrec [FileFormatDescriptor]
ReadPrec FileFormatDescriptor
Int -> ReadS FileFormatDescriptor
ReadS [FileFormatDescriptor]
(Int -> ReadS FileFormatDescriptor)
-> ReadS [FileFormatDescriptor]
-> ReadPrec FileFormatDescriptor
-> ReadPrec [FileFormatDescriptor]
-> Read FileFormatDescriptor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FileFormatDescriptor]
$creadListPrec :: ReadPrec [FileFormatDescriptor]
readPrec :: ReadPrec FileFormatDescriptor
$creadPrec :: ReadPrec FileFormatDescriptor
readList :: ReadS [FileFormatDescriptor]
$creadList :: ReadS [FileFormatDescriptor]
readsPrec :: Int -> ReadS FileFormatDescriptor
$creadsPrec :: Int -> ReadS FileFormatDescriptor
Prelude.Read, Int -> FileFormatDescriptor -> ShowS
[FileFormatDescriptor] -> ShowS
FileFormatDescriptor -> String
(Int -> FileFormatDescriptor -> ShowS)
-> (FileFormatDescriptor -> String)
-> ([FileFormatDescriptor] -> ShowS)
-> Show FileFormatDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileFormatDescriptor] -> ShowS
$cshowList :: [FileFormatDescriptor] -> ShowS
show :: FileFormatDescriptor -> String
$cshow :: FileFormatDescriptor -> String
showsPrec :: Int -> FileFormatDescriptor -> ShowS
$cshowsPrec :: Int -> FileFormatDescriptor -> ShowS
Prelude.Show, (forall x. FileFormatDescriptor -> Rep FileFormatDescriptor x)
-> (forall x. Rep FileFormatDescriptor x -> FileFormatDescriptor)
-> Generic FileFormatDescriptor
forall x. Rep FileFormatDescriptor x -> FileFormatDescriptor
forall x. FileFormatDescriptor -> Rep FileFormatDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FileFormatDescriptor x -> FileFormatDescriptor
$cfrom :: forall x. FileFormatDescriptor -> Rep FileFormatDescriptor x
Prelude.Generic)

-- |
-- Create a value of 'FileFormatDescriptor' 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:
--
-- 'jsonFormatDescriptor', 'fileFormatDescriptor_jsonFormatDescriptor' - Contains information about how a source JSON data file should be
-- analyzed.
--
-- 'csvFormatDescriptor', 'fileFormatDescriptor_csvFormatDescriptor' - Contains information about how a source CSV data file should be
-- analyzed.
newFileFormatDescriptor ::
  FileFormatDescriptor
newFileFormatDescriptor :: FileFormatDescriptor
newFileFormatDescriptor =
  FileFormatDescriptor' :: Maybe JsonFormatDescriptor
-> Maybe CsvFormatDescriptor -> FileFormatDescriptor
FileFormatDescriptor'
    { $sel:jsonFormatDescriptor:FileFormatDescriptor' :: Maybe JsonFormatDescriptor
jsonFormatDescriptor =
        Maybe JsonFormatDescriptor
forall a. Maybe a
Prelude.Nothing,
      $sel:csvFormatDescriptor:FileFormatDescriptor' :: Maybe CsvFormatDescriptor
csvFormatDescriptor = Maybe CsvFormatDescriptor
forall a. Maybe a
Prelude.Nothing
    }

-- | Contains information about how a source JSON data file should be
-- analyzed.
fileFormatDescriptor_jsonFormatDescriptor :: Lens.Lens' FileFormatDescriptor (Prelude.Maybe JsonFormatDescriptor)
fileFormatDescriptor_jsonFormatDescriptor :: (Maybe JsonFormatDescriptor -> f (Maybe JsonFormatDescriptor))
-> FileFormatDescriptor -> f FileFormatDescriptor
fileFormatDescriptor_jsonFormatDescriptor = (FileFormatDescriptor -> Maybe JsonFormatDescriptor)
-> (FileFormatDescriptor
    -> Maybe JsonFormatDescriptor -> FileFormatDescriptor)
-> Lens
     FileFormatDescriptor
     FileFormatDescriptor
     (Maybe JsonFormatDescriptor)
     (Maybe JsonFormatDescriptor)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileFormatDescriptor' {Maybe JsonFormatDescriptor
jsonFormatDescriptor :: Maybe JsonFormatDescriptor
$sel:jsonFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe JsonFormatDescriptor
jsonFormatDescriptor} -> Maybe JsonFormatDescriptor
jsonFormatDescriptor) (\s :: FileFormatDescriptor
s@FileFormatDescriptor' {} Maybe JsonFormatDescriptor
a -> FileFormatDescriptor
s {$sel:jsonFormatDescriptor:FileFormatDescriptor' :: Maybe JsonFormatDescriptor
jsonFormatDescriptor = Maybe JsonFormatDescriptor
a} :: FileFormatDescriptor)

-- | Contains information about how a source CSV data file should be
-- analyzed.
fileFormatDescriptor_csvFormatDescriptor :: Lens.Lens' FileFormatDescriptor (Prelude.Maybe CsvFormatDescriptor)
fileFormatDescriptor_csvFormatDescriptor :: (Maybe CsvFormatDescriptor -> f (Maybe CsvFormatDescriptor))
-> FileFormatDescriptor -> f FileFormatDescriptor
fileFormatDescriptor_csvFormatDescriptor = (FileFormatDescriptor -> Maybe CsvFormatDescriptor)
-> (FileFormatDescriptor
    -> Maybe CsvFormatDescriptor -> FileFormatDescriptor)
-> Lens
     FileFormatDescriptor
     FileFormatDescriptor
     (Maybe CsvFormatDescriptor)
     (Maybe CsvFormatDescriptor)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileFormatDescriptor' {Maybe CsvFormatDescriptor
csvFormatDescriptor :: Maybe CsvFormatDescriptor
$sel:csvFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe CsvFormatDescriptor
csvFormatDescriptor} -> Maybe CsvFormatDescriptor
csvFormatDescriptor) (\s :: FileFormatDescriptor
s@FileFormatDescriptor' {} Maybe CsvFormatDescriptor
a -> FileFormatDescriptor
s {$sel:csvFormatDescriptor:FileFormatDescriptor' :: Maybe CsvFormatDescriptor
csvFormatDescriptor = Maybe CsvFormatDescriptor
a} :: FileFormatDescriptor)

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

instance Prelude.Hashable FileFormatDescriptor

instance Prelude.NFData FileFormatDescriptor

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