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

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

-- | /See:/ 'newDeviceMethod' smart constructor.
data DeviceMethod = DeviceMethod'
  { -- | The type of the device, such as \"button\".
    DeviceMethod -> Maybe Text
deviceType :: Prelude.Maybe Prelude.Text,
    -- | The name of the method applicable to the deviceType.
    DeviceMethod -> Maybe Text
methodName :: Prelude.Maybe Prelude.Text
  }
  deriving (DeviceMethod -> DeviceMethod -> Bool
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]
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
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. 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:
--
-- 'deviceType', 'deviceMethod_deviceType' - The type of the device, such as \"button\".
--
-- 'methodName', 'deviceMethod_methodName' - The name of the method applicable to the deviceType.
newDeviceMethod ::
  DeviceMethod
newDeviceMethod :: DeviceMethod
newDeviceMethod =
  DeviceMethod'
    { $sel:deviceType:DeviceMethod' :: Maybe Text
deviceType = forall a. Maybe a
Prelude.Nothing,
      $sel:methodName:DeviceMethod' :: Maybe Text
methodName = forall a. Maybe a
Prelude.Nothing
    }

-- | The type of the device, such as \"button\".
deviceMethod_deviceType :: Lens.Lens' DeviceMethod (Prelude.Maybe Prelude.Text)
deviceMethod_deviceType :: Lens' DeviceMethod (Maybe Text)
deviceMethod_deviceType = 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)

-- | The name of the method applicable to the deviceType.
deviceMethod_methodName :: Lens.Lens' DeviceMethod (Prelude.Maybe Prelude.Text)
deviceMethod_methodName :: Lens' DeviceMethod (Maybe Text)
deviceMethod_methodName = 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)

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

instance Prelude.Hashable DeviceMethod where
  hashWithSalt :: Int -> DeviceMethod -> Int
hashWithSalt Int
_salt DeviceMethod' {Maybe Text
methodName :: Maybe Text
deviceType :: Maybe Text
$sel:methodName:DeviceMethod' :: DeviceMethod -> Maybe Text
$sel:deviceType:DeviceMethod' :: DeviceMethod -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
deviceType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
methodName

instance Prelude.NFData DeviceMethod where
  rnf :: DeviceMethod -> ()
rnf DeviceMethod' {Maybe Text
methodName :: Maybe Text
deviceType :: Maybe Text
$sel:methodName:DeviceMethod' :: DeviceMethod -> Maybe Text
$sel:deviceType:DeviceMethod' :: DeviceMethod -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
deviceType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
methodName

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