{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.LookoutMetrics.Types.FileFormatDescriptor where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 CSV data file should be
    -- analyzed.
    FileFormatDescriptor -> Maybe CsvFormatDescriptor
csvFormatDescriptor :: Prelude.Maybe CsvFormatDescriptor,
    -- | Contains information about how a source JSON data file should be
    -- analyzed.
    FileFormatDescriptor -> Maybe JsonFormatDescriptor
jsonFormatDescriptor :: Prelude.Maybe JsonFormatDescriptor
  }
  deriving (FileFormatDescriptor -> FileFormatDescriptor -> Bool
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]
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
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. 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:
--
-- 'csvFormatDescriptor', 'fileFormatDescriptor_csvFormatDescriptor' - Contains information about how a source CSV data file should be
-- analyzed.
--
-- 'jsonFormatDescriptor', 'fileFormatDescriptor_jsonFormatDescriptor' - Contains information about how a source JSON data file should be
-- analyzed.
newFileFormatDescriptor ::
  FileFormatDescriptor
newFileFormatDescriptor :: FileFormatDescriptor
newFileFormatDescriptor =
  FileFormatDescriptor'
    { $sel:csvFormatDescriptor:FileFormatDescriptor' :: Maybe CsvFormatDescriptor
csvFormatDescriptor =
        forall a. Maybe a
Prelude.Nothing,
      $sel:jsonFormatDescriptor:FileFormatDescriptor' :: Maybe JsonFormatDescriptor
jsonFormatDescriptor = forall a. Maybe a
Prelude.Nothing
    }

-- | Contains information about how a source CSV data file should be
-- analyzed.
fileFormatDescriptor_csvFormatDescriptor :: Lens.Lens' FileFormatDescriptor (Prelude.Maybe CsvFormatDescriptor)
fileFormatDescriptor_csvFormatDescriptor :: Lens' FileFormatDescriptor (Maybe CsvFormatDescriptor)
fileFormatDescriptor_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)

-- | Contains information about how a source JSON data file should be
-- analyzed.
fileFormatDescriptor_jsonFormatDescriptor :: Lens.Lens' FileFormatDescriptor (Prelude.Maybe JsonFormatDescriptor)
fileFormatDescriptor_jsonFormatDescriptor :: Lens' FileFormatDescriptor (Maybe JsonFormatDescriptor)
fileFormatDescriptor_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)

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

instance Prelude.Hashable FileFormatDescriptor where
  hashWithSalt :: Int -> FileFormatDescriptor -> Int
hashWithSalt Int
_salt FileFormatDescriptor' {Maybe CsvFormatDescriptor
Maybe JsonFormatDescriptor
jsonFormatDescriptor :: Maybe JsonFormatDescriptor
csvFormatDescriptor :: Maybe CsvFormatDescriptor
$sel:jsonFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe JsonFormatDescriptor
$sel:csvFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe CsvFormatDescriptor
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CsvFormatDescriptor
csvFormatDescriptor
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe JsonFormatDescriptor
jsonFormatDescriptor

instance Prelude.NFData FileFormatDescriptor where
  rnf :: FileFormatDescriptor -> ()
rnf FileFormatDescriptor' {Maybe CsvFormatDescriptor
Maybe JsonFormatDescriptor
jsonFormatDescriptor :: Maybe JsonFormatDescriptor
csvFormatDescriptor :: Maybe CsvFormatDescriptor
$sel:jsonFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe JsonFormatDescriptor
$sel:csvFormatDescriptor:FileFormatDescriptor' :: FileFormatDescriptor -> Maybe CsvFormatDescriptor
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CsvFormatDescriptor
csvFormatDescriptor
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe JsonFormatDescriptor
jsonFormatDescriptor

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