{-# 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.Greengrass.Types.Device
-- 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.Greengrass.Types.Device 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

-- | Information about a device.
--
-- /See:/ 'newDevice' smart constructor.
data Device = Device'
  { -- | If true, the device\'s local shadow will be automatically synced with
    -- the cloud.
    Device -> Maybe Bool
syncShadow :: Prelude.Maybe Prelude.Bool,
    -- | The thing ARN of the device.
    Device -> Text
thingArn :: Prelude.Text,
    -- | A descriptive or arbitrary ID for the device. This value must be unique
    -- within the device definition version. Max length is 128 characters with
    -- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
    Device -> Text
id :: Prelude.Text,
    -- | The ARN of the certificate associated with the device.
    Device -> Text
certificateArn :: Prelude.Text
  }
  deriving (Device -> Device -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Device -> Device -> Bool
$c/= :: Device -> Device -> Bool
== :: Device -> Device -> Bool
$c== :: Device -> Device -> Bool
Prelude.Eq, ReadPrec [Device]
ReadPrec Device
Int -> ReadS Device
ReadS [Device]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Device]
$creadListPrec :: ReadPrec [Device]
readPrec :: ReadPrec Device
$creadPrec :: ReadPrec Device
readList :: ReadS [Device]
$creadList :: ReadS [Device]
readsPrec :: Int -> ReadS Device
$creadsPrec :: Int -> ReadS Device
Prelude.Read, Int -> Device -> ShowS
[Device] -> ShowS
Device -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Device] -> ShowS
$cshowList :: [Device] -> ShowS
show :: Device -> String
$cshow :: Device -> String
showsPrec :: Int -> Device -> ShowS
$cshowsPrec :: Int -> Device -> ShowS
Prelude.Show, forall x. Rep Device x -> Device
forall x. Device -> Rep Device x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Device x -> Device
$cfrom :: forall x. Device -> Rep Device x
Prelude.Generic)

-- |
-- Create a value of 'Device' 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:
--
-- 'syncShadow', 'device_syncShadow' - If true, the device\'s local shadow will be automatically synced with
-- the cloud.
--
-- 'thingArn', 'device_thingArn' - The thing ARN of the device.
--
-- 'id', 'device_id' - A descriptive or arbitrary ID for the device. This value must be unique
-- within the device definition version. Max length is 128 characters with
-- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
--
-- 'certificateArn', 'device_certificateArn' - The ARN of the certificate associated with the device.
newDevice ::
  -- | 'thingArn'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  -- | 'certificateArn'
  Prelude.Text ->
  Device
newDevice :: Text -> Text -> Text -> Device
newDevice Text
pThingArn_ Text
pId_ Text
pCertificateArn_ =
  Device'
    { $sel:syncShadow:Device' :: Maybe Bool
syncShadow = forall a. Maybe a
Prelude.Nothing,
      $sel:thingArn:Device' :: Text
thingArn = Text
pThingArn_,
      $sel:id:Device' :: Text
id = Text
pId_,
      $sel:certificateArn:Device' :: Text
certificateArn = Text
pCertificateArn_
    }

-- | If true, the device\'s local shadow will be automatically synced with
-- the cloud.
device_syncShadow :: Lens.Lens' Device (Prelude.Maybe Prelude.Bool)
device_syncShadow :: Lens' Device (Maybe Bool)
device_syncShadow = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Device' {Maybe Bool
syncShadow :: Maybe Bool
$sel:syncShadow:Device' :: Device -> Maybe Bool
syncShadow} -> Maybe Bool
syncShadow) (\s :: Device
s@Device' {} Maybe Bool
a -> Device
s {$sel:syncShadow:Device' :: Maybe Bool
syncShadow = Maybe Bool
a} :: Device)

-- | The thing ARN of the device.
device_thingArn :: Lens.Lens' Device Prelude.Text
device_thingArn :: Lens' Device Text
device_thingArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Device' {Text
thingArn :: Text
$sel:thingArn:Device' :: Device -> Text
thingArn} -> Text
thingArn) (\s :: Device
s@Device' {} Text
a -> Device
s {$sel:thingArn:Device' :: Text
thingArn = Text
a} :: Device)

-- | A descriptive or arbitrary ID for the device. This value must be unique
-- within the device definition version. Max length is 128 characters with
-- pattern \'\'[a-zA-Z0-9:_-]+\'\'.
device_id :: Lens.Lens' Device Prelude.Text
device_id :: Lens' Device Text
device_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Device' {Text
id :: Text
$sel:id:Device' :: Device -> Text
id} -> Text
id) (\s :: Device
s@Device' {} Text
a -> Device
s {$sel:id:Device' :: Text
id = Text
a} :: Device)

-- | The ARN of the certificate associated with the device.
device_certificateArn :: Lens.Lens' Device Prelude.Text
device_certificateArn :: Lens' Device Text
device_certificateArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Device' {Text
certificateArn :: Text
$sel:certificateArn:Device' :: Device -> Text
certificateArn} -> Text
certificateArn) (\s :: Device
s@Device' {} Text
a -> Device
s {$sel:certificateArn:Device' :: Text
certificateArn = Text
a} :: Device)

instance Data.FromJSON Device where
  parseJSON :: Value -> Parser Device
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Device"
      ( \Object
x ->
          Maybe Bool -> Text -> Text -> Text -> Device
Device'
            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
"SyncShadow")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ThingArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Id")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"CertificateArn")
      )

instance Prelude.Hashable Device where
  hashWithSalt :: Int -> Device -> Int
hashWithSalt Int
_salt Device' {Maybe Bool
Text
certificateArn :: Text
id :: Text
thingArn :: Text
syncShadow :: Maybe Bool
$sel:certificateArn:Device' :: Device -> Text
$sel:id:Device' :: Device -> Text
$sel:thingArn:Device' :: Device -> Text
$sel:syncShadow:Device' :: Device -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
syncShadow
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
thingArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateArn

instance Prelude.NFData Device where
  rnf :: Device -> ()
rnf Device' {Maybe Bool
Text
certificateArn :: Text
id :: Text
thingArn :: Text
syncShadow :: Maybe Bool
$sel:certificateArn:Device' :: Device -> Text
$sel:id:Device' :: Device -> Text
$sel:thingArn:Device' :: Device -> Text
$sel:syncShadow:Device' :: Device -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
syncShadow
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
thingArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
certificateArn

instance Data.ToJSON Device where
  toJSON :: Device -> Value
toJSON Device' {Maybe Bool
Text
certificateArn :: Text
id :: Text
thingArn :: Text
syncShadow :: Maybe Bool
$sel:certificateArn:Device' :: Device -> Text
$sel:id:Device' :: Device -> Text
$sel:thingArn:Device' :: Device -> Text
$sel:syncShadow:Device' :: Device -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SyncShadow" 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 Bool
syncShadow,
            forall a. a -> Maybe a
Prelude.Just (Key
"ThingArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
thingArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CertificateArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
certificateArn)
          ]
      )