{-# 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 #-}
module Amazonka.IoT.Types.Field where
import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.FieldType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
data Field = Field'
{
Field -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
Field -> Maybe FieldType
type' :: Prelude.Maybe FieldType
}
deriving (Field -> Field -> Bool
(Field -> Field -> Bool) -> (Field -> Field -> Bool) -> Eq Field
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Field -> Field -> Bool
$c/= :: Field -> Field -> Bool
== :: Field -> Field -> Bool
$c== :: Field -> Field -> Bool
Prelude.Eq, ReadPrec [Field]
ReadPrec Field
Int -> ReadS Field
ReadS [Field]
(Int -> ReadS Field)
-> ReadS [Field]
-> ReadPrec Field
-> ReadPrec [Field]
-> Read Field
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Field]
$creadListPrec :: ReadPrec [Field]
readPrec :: ReadPrec Field
$creadPrec :: ReadPrec Field
readList :: ReadS [Field]
$creadList :: ReadS [Field]
readsPrec :: Int -> ReadS Field
$creadsPrec :: Int -> ReadS Field
Prelude.Read, Int -> Field -> ShowS
[Field] -> ShowS
Field -> String
(Int -> Field -> ShowS)
-> (Field -> String) -> ([Field] -> ShowS) -> Show Field
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Field] -> ShowS
$cshowList :: [Field] -> ShowS
show :: Field -> String
$cshow :: Field -> String
showsPrec :: Int -> Field -> ShowS
$cshowsPrec :: Int -> Field -> ShowS
Prelude.Show, (forall x. Field -> Rep Field x)
-> (forall x. Rep Field x -> Field) -> Generic Field
forall x. Rep Field x -> Field
forall x. Field -> Rep Field x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Field x -> Field
$cfrom :: forall x. Field -> Rep Field x
Prelude.Generic)
newField ::
Field
newField :: Field
newField =
Field' :: Maybe Text -> Maybe FieldType -> Field
Field'
{ $sel:name:Field' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
$sel:type':Field' :: Maybe FieldType
type' = Maybe FieldType
forall a. Maybe a
Prelude.Nothing
}
field_name :: Lens.Lens' Field (Prelude.Maybe Prelude.Text)
field_name :: (Maybe Text -> f (Maybe Text)) -> Field -> f Field
field_name = (Field -> Maybe Text)
-> (Field -> Maybe Text -> Field)
-> Lens Field Field (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Text
name :: Maybe Text
$sel:name:Field' :: Field -> Maybe Text
name} -> Maybe Text
name) (\s :: Field
s@Field' {} Maybe Text
a -> Field
s {$sel:name:Field' :: Maybe Text
name = Maybe Text
a} :: Field)
field_type :: Lens.Lens' Field (Prelude.Maybe FieldType)
field_type :: (Maybe FieldType -> f (Maybe FieldType)) -> Field -> f Field
field_type = (Field -> Maybe FieldType)
-> (Field -> Maybe FieldType -> Field)
-> Lens Field Field (Maybe FieldType) (Maybe FieldType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe FieldType
type' :: Maybe FieldType
$sel:type':Field' :: Field -> Maybe FieldType
type'} -> Maybe FieldType
type') (\s :: Field
s@Field' {} Maybe FieldType
a -> Field
s {$sel:type':Field' :: Maybe FieldType
type' = Maybe FieldType
a} :: Field)
instance Core.FromJSON Field where
parseJSON :: Value -> Parser Field
parseJSON =
String -> (Object -> Parser Field) -> Value -> Parser Field
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
String
"Field"
( \Object
x ->
Maybe Text -> Maybe FieldType -> Field
Field'
(Maybe Text -> Maybe FieldType -> Field)
-> Parser (Maybe Text) -> Parser (Maybe FieldType -> Field)
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
"name") Parser (Maybe FieldType -> Field)
-> Parser (Maybe FieldType) -> Parser Field
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe FieldType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
)
instance Prelude.Hashable Field
instance Prelude.NFData Field
instance Core.ToJSON Field where
toJSON :: Field -> Value
toJSON Field' {Maybe Text
Maybe FieldType
type' :: Maybe FieldType
name :: Maybe Text
$sel:type':Field' :: Field -> Maybe FieldType
$sel:name:Field' :: Field -> Maybe Text
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"name" 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
name,
(Text
"type" Text -> FieldType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (FieldType -> Pair) -> Maybe FieldType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FieldType
type'
]
)