{-# 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.IoTFleetWise.Types.SignalDecoder
-- 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.IoTFleetWise.Types.SignalDecoder where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTFleetWise.Types.CanSignal
import Amazonka.IoTFleetWise.Types.ObdSignal
import Amazonka.IoTFleetWise.Types.SignalDecoderType
import qualified Amazonka.Prelude as Prelude

-- | Information about a signal decoder.
--
-- /See:/ 'newSignalDecoder' smart constructor.
data SignalDecoder = SignalDecoder'
  { -- | Information about signal decoder using the Controller Area Network (CAN)
    -- protocol.
    SignalDecoder -> Maybe CanSignal
canSignal :: Prelude.Maybe CanSignal,
    -- | Information about signal decoder using the On-board diagnostic (OBD) II
    -- protocol.
    SignalDecoder -> Maybe ObdSignal
obdSignal :: Prelude.Maybe ObdSignal,
    -- | The fully qualified name of a signal decoder as defined in a vehicle
    -- model.
    SignalDecoder -> Text
fullyQualifiedName :: Prelude.Text,
    -- | The network protocol for the vehicle. For example, @CAN_SIGNAL@
    -- specifies a protocol that defines how data is communicated between
    -- electronic control units (ECUs). @OBD_SIGNAL@ specifies a protocol that
    -- defines how self-diagnostic data is communicated between ECUs.
    SignalDecoder -> SignalDecoderType
type' :: SignalDecoderType,
    -- | The ID of a network interface that specifies what network protocol a
    -- vehicle follows.
    SignalDecoder -> Text
interfaceId :: Prelude.Text
  }
  deriving (SignalDecoder -> SignalDecoder -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignalDecoder -> SignalDecoder -> Bool
$c/= :: SignalDecoder -> SignalDecoder -> Bool
== :: SignalDecoder -> SignalDecoder -> Bool
$c== :: SignalDecoder -> SignalDecoder -> Bool
Prelude.Eq, ReadPrec [SignalDecoder]
ReadPrec SignalDecoder
Int -> ReadS SignalDecoder
ReadS [SignalDecoder]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SignalDecoder]
$creadListPrec :: ReadPrec [SignalDecoder]
readPrec :: ReadPrec SignalDecoder
$creadPrec :: ReadPrec SignalDecoder
readList :: ReadS [SignalDecoder]
$creadList :: ReadS [SignalDecoder]
readsPrec :: Int -> ReadS SignalDecoder
$creadsPrec :: Int -> ReadS SignalDecoder
Prelude.Read, Int -> SignalDecoder -> ShowS
[SignalDecoder] -> ShowS
SignalDecoder -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignalDecoder] -> ShowS
$cshowList :: [SignalDecoder] -> ShowS
show :: SignalDecoder -> String
$cshow :: SignalDecoder -> String
showsPrec :: Int -> SignalDecoder -> ShowS
$cshowsPrec :: Int -> SignalDecoder -> ShowS
Prelude.Show, forall x. Rep SignalDecoder x -> SignalDecoder
forall x. SignalDecoder -> Rep SignalDecoder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SignalDecoder x -> SignalDecoder
$cfrom :: forall x. SignalDecoder -> Rep SignalDecoder x
Prelude.Generic)

-- |
-- Create a value of 'SignalDecoder' 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:
--
-- 'canSignal', 'signalDecoder_canSignal' - Information about signal decoder using the Controller Area Network (CAN)
-- protocol.
--
-- 'obdSignal', 'signalDecoder_obdSignal' - Information about signal decoder using the On-board diagnostic (OBD) II
-- protocol.
--
-- 'fullyQualifiedName', 'signalDecoder_fullyQualifiedName' - The fully qualified name of a signal decoder as defined in a vehicle
-- model.
--
-- 'type'', 'signalDecoder_type' - The network protocol for the vehicle. For example, @CAN_SIGNAL@
-- specifies a protocol that defines how data is communicated between
-- electronic control units (ECUs). @OBD_SIGNAL@ specifies a protocol that
-- defines how self-diagnostic data is communicated between ECUs.
--
-- 'interfaceId', 'signalDecoder_interfaceId' - The ID of a network interface that specifies what network protocol a
-- vehicle follows.
newSignalDecoder ::
  -- | 'fullyQualifiedName'
  Prelude.Text ->
  -- | 'type''
  SignalDecoderType ->
  -- | 'interfaceId'
  Prelude.Text ->
  SignalDecoder
newSignalDecoder :: Text -> SignalDecoderType -> Text -> SignalDecoder
newSignalDecoder
  Text
pFullyQualifiedName_
  SignalDecoderType
pType_
  Text
pInterfaceId_ =
    SignalDecoder'
      { $sel:canSignal:SignalDecoder' :: Maybe CanSignal
canSignal = forall a. Maybe a
Prelude.Nothing,
        $sel:obdSignal:SignalDecoder' :: Maybe ObdSignal
obdSignal = forall a. Maybe a
Prelude.Nothing,
        $sel:fullyQualifiedName:SignalDecoder' :: Text
fullyQualifiedName = Text
pFullyQualifiedName_,
        $sel:type':SignalDecoder' :: SignalDecoderType
type' = SignalDecoderType
pType_,
        $sel:interfaceId:SignalDecoder' :: Text
interfaceId = Text
pInterfaceId_
      }

-- | Information about signal decoder using the Controller Area Network (CAN)
-- protocol.
signalDecoder_canSignal :: Lens.Lens' SignalDecoder (Prelude.Maybe CanSignal)
signalDecoder_canSignal :: Lens' SignalDecoder (Maybe CanSignal)
signalDecoder_canSignal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignalDecoder' {Maybe CanSignal
canSignal :: Maybe CanSignal
$sel:canSignal:SignalDecoder' :: SignalDecoder -> Maybe CanSignal
canSignal} -> Maybe CanSignal
canSignal) (\s :: SignalDecoder
s@SignalDecoder' {} Maybe CanSignal
a -> SignalDecoder
s {$sel:canSignal:SignalDecoder' :: Maybe CanSignal
canSignal = Maybe CanSignal
a} :: SignalDecoder)

-- | Information about signal decoder using the On-board diagnostic (OBD) II
-- protocol.
signalDecoder_obdSignal :: Lens.Lens' SignalDecoder (Prelude.Maybe ObdSignal)
signalDecoder_obdSignal :: Lens' SignalDecoder (Maybe ObdSignal)
signalDecoder_obdSignal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignalDecoder' {Maybe ObdSignal
obdSignal :: Maybe ObdSignal
$sel:obdSignal:SignalDecoder' :: SignalDecoder -> Maybe ObdSignal
obdSignal} -> Maybe ObdSignal
obdSignal) (\s :: SignalDecoder
s@SignalDecoder' {} Maybe ObdSignal
a -> SignalDecoder
s {$sel:obdSignal:SignalDecoder' :: Maybe ObdSignal
obdSignal = Maybe ObdSignal
a} :: SignalDecoder)

-- | The fully qualified name of a signal decoder as defined in a vehicle
-- model.
signalDecoder_fullyQualifiedName :: Lens.Lens' SignalDecoder Prelude.Text
signalDecoder_fullyQualifiedName :: Lens' SignalDecoder Text
signalDecoder_fullyQualifiedName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignalDecoder' {Text
fullyQualifiedName :: Text
$sel:fullyQualifiedName:SignalDecoder' :: SignalDecoder -> Text
fullyQualifiedName} -> Text
fullyQualifiedName) (\s :: SignalDecoder
s@SignalDecoder' {} Text
a -> SignalDecoder
s {$sel:fullyQualifiedName:SignalDecoder' :: Text
fullyQualifiedName = Text
a} :: SignalDecoder)

-- | The network protocol for the vehicle. For example, @CAN_SIGNAL@
-- specifies a protocol that defines how data is communicated between
-- electronic control units (ECUs). @OBD_SIGNAL@ specifies a protocol that
-- defines how self-diagnostic data is communicated between ECUs.
signalDecoder_type :: Lens.Lens' SignalDecoder SignalDecoderType
signalDecoder_type :: Lens' SignalDecoder SignalDecoderType
signalDecoder_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignalDecoder' {SignalDecoderType
type' :: SignalDecoderType
$sel:type':SignalDecoder' :: SignalDecoder -> SignalDecoderType
type'} -> SignalDecoderType
type') (\s :: SignalDecoder
s@SignalDecoder' {} SignalDecoderType
a -> SignalDecoder
s {$sel:type':SignalDecoder' :: SignalDecoderType
type' = SignalDecoderType
a} :: SignalDecoder)

-- | The ID of a network interface that specifies what network protocol a
-- vehicle follows.
signalDecoder_interfaceId :: Lens.Lens' SignalDecoder Prelude.Text
signalDecoder_interfaceId :: Lens' SignalDecoder Text
signalDecoder_interfaceId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignalDecoder' {Text
interfaceId :: Text
$sel:interfaceId:SignalDecoder' :: SignalDecoder -> Text
interfaceId} -> Text
interfaceId) (\s :: SignalDecoder
s@SignalDecoder' {} Text
a -> SignalDecoder
s {$sel:interfaceId:SignalDecoder' :: Text
interfaceId = Text
a} :: SignalDecoder)

instance Data.FromJSON SignalDecoder where
  parseJSON :: Value -> Parser SignalDecoder
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SignalDecoder"
      ( \Object
x ->
          Maybe CanSignal
-> Maybe ObdSignal
-> Text
-> SignalDecoderType
-> Text
-> SignalDecoder
SignalDecoder'
            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
"canSignal")
            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
"obdSignal")
            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
"fullyQualifiedName")
            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
"type")
            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
"interfaceId")
      )

instance Prelude.Hashable SignalDecoder where
  hashWithSalt :: Int -> SignalDecoder -> Int
hashWithSalt Int
_salt SignalDecoder' {Maybe CanSignal
Maybe ObdSignal
Text
SignalDecoderType
interfaceId :: Text
type' :: SignalDecoderType
fullyQualifiedName :: Text
obdSignal :: Maybe ObdSignal
canSignal :: Maybe CanSignal
$sel:interfaceId:SignalDecoder' :: SignalDecoder -> Text
$sel:type':SignalDecoder' :: SignalDecoder -> SignalDecoderType
$sel:fullyQualifiedName:SignalDecoder' :: SignalDecoder -> Text
$sel:obdSignal:SignalDecoder' :: SignalDecoder -> Maybe ObdSignal
$sel:canSignal:SignalDecoder' :: SignalDecoder -> Maybe CanSignal
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CanSignal
canSignal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ObdSignal
obdSignal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
fullyQualifiedName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SignalDecoderType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
interfaceId

instance Prelude.NFData SignalDecoder where
  rnf :: SignalDecoder -> ()
rnf SignalDecoder' {Maybe CanSignal
Maybe ObdSignal
Text
SignalDecoderType
interfaceId :: Text
type' :: SignalDecoderType
fullyQualifiedName :: Text
obdSignal :: Maybe ObdSignal
canSignal :: Maybe CanSignal
$sel:interfaceId:SignalDecoder' :: SignalDecoder -> Text
$sel:type':SignalDecoder' :: SignalDecoder -> SignalDecoderType
$sel:fullyQualifiedName:SignalDecoder' :: SignalDecoder -> Text
$sel:obdSignal:SignalDecoder' :: SignalDecoder -> Maybe ObdSignal
$sel:canSignal:SignalDecoder' :: SignalDecoder -> Maybe CanSignal
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CanSignal
canSignal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ObdSignal
obdSignal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
fullyQualifiedName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SignalDecoderType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
interfaceId

instance Data.ToJSON SignalDecoder where
  toJSON :: SignalDecoder -> Value
toJSON SignalDecoder' {Maybe CanSignal
Maybe ObdSignal
Text
SignalDecoderType
interfaceId :: Text
type' :: SignalDecoderType
fullyQualifiedName :: Text
obdSignal :: Maybe ObdSignal
canSignal :: Maybe CanSignal
$sel:interfaceId:SignalDecoder' :: SignalDecoder -> Text
$sel:type':SignalDecoder' :: SignalDecoder -> SignalDecoderType
$sel:fullyQualifiedName:SignalDecoder' :: SignalDecoder -> Text
$sel:obdSignal:SignalDecoder' :: SignalDecoder -> Maybe ObdSignal
$sel:canSignal:SignalDecoder' :: SignalDecoder -> Maybe CanSignal
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"canSignal" 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 CanSignal
canSignal,
            (Key
"obdSignal" 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 ObdSignal
obdSignal,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"fullyQualifiedName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
fullyQualifiedName),
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SignalDecoderType
type'),
            forall a. a -> Maybe a
Prelude.Just (Key
"interfaceId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
interfaceId)
          ]
      )