{-# 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.IoT1ClickDevices.Types.DeviceMethod
-- 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.IoT1ClickDevices.Types.DeviceMethod where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | /See:/ 'newDeviceMethod' smart constructor.
data DeviceMethod = DeviceMethod'
  { -- | The name of the method applicable to the deviceType.
    DeviceMethod -> Maybe Text
methodName :: Prelude.Maybe Prelude.Text,
    -- | The type of the device, such as \"button\".
    DeviceMethod -> Maybe Text
deviceType :: Prelude.Maybe Prelude.Text
  }
  deriving (DeviceMethod -> DeviceMethod -> Bool
(DeviceMethod -> DeviceMethod -> Bool)
-> (DeviceMethod -> DeviceMethod -> Bool) -> Eq DeviceMethod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeviceMethod -> DeviceMethod -> Bool
$c/= :: DeviceMethod -> DeviceMethod -> Bool
== :: DeviceMethod -> DeviceMethod -> Bool
$c== :: DeviceMethod -> DeviceMethod -> Bool
Prelude.Eq, ReadPrec [DeviceMethod]
ReadPrec DeviceMethod
Int -> ReadS DeviceMethod
ReadS [DeviceMethod]
(Int -> ReadS DeviceMethod)
-> ReadS [DeviceMethod]
-> ReadPrec DeviceMethod
-> ReadPrec [DeviceMethod]
-> Read DeviceMethod
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeviceMethod]
$creadListPrec :: ReadPrec [DeviceMethod]
readPrec :: ReadPrec DeviceMethod
$creadPrec :: ReadPrec DeviceMethod
readList :: ReadS [DeviceMethod]
$creadList :: ReadS [DeviceMethod]
readsPrec :: Int -> ReadS DeviceMethod
$creadsPrec :: Int -> ReadS DeviceMethod
Prelude.Read, Int -> DeviceMethod -> ShowS
[DeviceMethod] -> ShowS
DeviceMethod -> String
(Int -> DeviceMethod -> ShowS)
-> (DeviceMethod -> String)
-> ([DeviceMethod] -> ShowS)
-> Show DeviceMethod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeviceMethod] -> ShowS
$cshowList :: [DeviceMethod] -> ShowS
show :: DeviceMethod -> String
$cshow :: DeviceMethod -> String
showsPrec :: Int -> DeviceMethod -> ShowS
$cshowsPrec :: Int -> DeviceMethod -> ShowS
Prelude.Show, (forall x. DeviceMethod -> Rep DeviceMethod x)
-> (forall x. Rep DeviceMethod x -> DeviceMethod)
-> Generic DeviceMethod
forall x. Rep DeviceMethod x -> DeviceMethod
forall x. DeviceMethod -> Rep DeviceMethod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeviceMethod x -> DeviceMethod
$cfrom :: forall x. DeviceMethod -> Rep DeviceMethod x
Prelude.Generic)

-- |
-- Create a value of 'DeviceMethod' 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:
--
-- 'methodName', 'deviceMethod_methodName' - The name of the method applicable to the deviceType.
--
-- 'deviceType', 'deviceMethod_deviceType' - The type of the device, such as \"button\".
newDeviceMethod ::
  DeviceMethod
newDeviceMethod :: DeviceMethod
newDeviceMethod =
  DeviceMethod' :: Maybe Text -> Maybe Text -> DeviceMethod
DeviceMethod'
    { $sel:methodName:DeviceMethod' :: Maybe Text
methodName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:deviceType:DeviceMethod' :: Maybe Text
deviceType = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the method applicable to the deviceType.
deviceMethod_methodName :: Lens.Lens' DeviceMethod (Prelude.Maybe Prelude.Text)
deviceMethod_methodName :: (Maybe Text -> f (Maybe Text)) -> DeviceMethod -> f DeviceMethod
deviceMethod_methodName = (DeviceMethod -> Maybe Text)
-> (DeviceMethod -> Maybe Text -> DeviceMethod)
-> Lens DeviceMethod DeviceMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceMethod' {Maybe Text
methodName :: Maybe Text
$sel:methodName:DeviceMethod' :: DeviceMethod -> Maybe Text
methodName} -> Maybe Text
methodName) (\s :: DeviceMethod
s@DeviceMethod' {} Maybe Text
a -> DeviceMethod
s {$sel:methodName:DeviceMethod' :: Maybe Text
methodName = Maybe Text
a} :: DeviceMethod)

-- | The type of the device, such as \"button\".
deviceMethod_deviceType :: Lens.Lens' DeviceMethod (Prelude.Maybe Prelude.Text)
deviceMethod_deviceType :: (Maybe Text -> f (Maybe Text)) -> DeviceMethod -> f DeviceMethod
deviceMethod_deviceType = (DeviceMethod -> Maybe Text)
-> (DeviceMethod -> Maybe Text -> DeviceMethod)
-> Lens DeviceMethod DeviceMethod (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceMethod' {Maybe Text
deviceType :: Maybe Text
$sel:deviceType:DeviceMethod' :: DeviceMethod -> Maybe Text
deviceType} -> Maybe Text
deviceType) (\s :: DeviceMethod
s@DeviceMethod' {} Maybe Text
a -> DeviceMethod
s {$sel:deviceType:DeviceMethod' :: Maybe Text
deviceType = Maybe Text
a} :: DeviceMethod)

instance Core.FromJSON DeviceMethod where
  parseJSON :: Value -> Parser DeviceMethod
parseJSON =
    String
-> (Object -> Parser DeviceMethod) -> Value -> Parser DeviceMethod
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeviceMethod"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> DeviceMethod
DeviceMethod'
            (Maybe Text -> Maybe Text -> DeviceMethod)
-> Parser (Maybe Text) -> Parser (Maybe Text -> DeviceMethod)
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
"methodName")
            Parser (Maybe Text -> DeviceMethod)
-> Parser (Maybe Text) -> Parser DeviceMethod
forall (f :: * -> *) a b. Applicative f => 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
"deviceType")
      )

instance Prelude.Hashable DeviceMethod

instance Prelude.NFData DeviceMethod

instance Core.ToJSON DeviceMethod where
  toJSON :: DeviceMethod -> Value
toJSON DeviceMethod' {Maybe Text
deviceType :: Maybe Text
methodName :: Maybe Text
$sel:deviceType:DeviceMethod' :: DeviceMethod -> Maybe Text
$sel:methodName:DeviceMethod' :: DeviceMethod -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"methodName" 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
methodName,
            (Text
"deviceType" 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
deviceType
          ]
      )