{-# 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.IoT.Types.OTAUpdateFile
-- 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.IoT.Types.OTAUpdateFile where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.CodeSigning
import Amazonka.IoT.Types.FileLocation
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a file to be associated with an OTA update.
--
-- /See:/ 'newOTAUpdateFile' smart constructor.
data OTAUpdateFile = OTAUpdateFile'
  { -- | The location of the updated firmware.
    OTAUpdateFile -> Maybe FileLocation
fileLocation :: Prelude.Maybe FileLocation,
    -- | An integer value you can include in the job document to allow your
    -- devices to identify the type of file received from the cloud.
    OTAUpdateFile -> Maybe Natural
fileType :: Prelude.Maybe Prelude.Natural,
    -- | The file version.
    OTAUpdateFile -> Maybe Text
fileVersion :: Prelude.Maybe Prelude.Text,
    -- | A list of name\/attribute pairs.
    OTAUpdateFile -> Maybe (HashMap Text Text)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The code signing method of the file.
    OTAUpdateFile -> Maybe CodeSigning
codeSigning :: Prelude.Maybe CodeSigning,
    -- | The name of the file.
    OTAUpdateFile -> Maybe Text
fileName :: Prelude.Maybe Prelude.Text
  }
  deriving (OTAUpdateFile -> OTAUpdateFile -> Bool
(OTAUpdateFile -> OTAUpdateFile -> Bool)
-> (OTAUpdateFile -> OTAUpdateFile -> Bool) -> Eq OTAUpdateFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OTAUpdateFile -> OTAUpdateFile -> Bool
$c/= :: OTAUpdateFile -> OTAUpdateFile -> Bool
== :: OTAUpdateFile -> OTAUpdateFile -> Bool
$c== :: OTAUpdateFile -> OTAUpdateFile -> Bool
Prelude.Eq, ReadPrec [OTAUpdateFile]
ReadPrec OTAUpdateFile
Int -> ReadS OTAUpdateFile
ReadS [OTAUpdateFile]
(Int -> ReadS OTAUpdateFile)
-> ReadS [OTAUpdateFile]
-> ReadPrec OTAUpdateFile
-> ReadPrec [OTAUpdateFile]
-> Read OTAUpdateFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OTAUpdateFile]
$creadListPrec :: ReadPrec [OTAUpdateFile]
readPrec :: ReadPrec OTAUpdateFile
$creadPrec :: ReadPrec OTAUpdateFile
readList :: ReadS [OTAUpdateFile]
$creadList :: ReadS [OTAUpdateFile]
readsPrec :: Int -> ReadS OTAUpdateFile
$creadsPrec :: Int -> ReadS OTAUpdateFile
Prelude.Read, Int -> OTAUpdateFile -> ShowS
[OTAUpdateFile] -> ShowS
OTAUpdateFile -> String
(Int -> OTAUpdateFile -> ShowS)
-> (OTAUpdateFile -> String)
-> ([OTAUpdateFile] -> ShowS)
-> Show OTAUpdateFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OTAUpdateFile] -> ShowS
$cshowList :: [OTAUpdateFile] -> ShowS
show :: OTAUpdateFile -> String
$cshow :: OTAUpdateFile -> String
showsPrec :: Int -> OTAUpdateFile -> ShowS
$cshowsPrec :: Int -> OTAUpdateFile -> ShowS
Prelude.Show, (forall x. OTAUpdateFile -> Rep OTAUpdateFile x)
-> (forall x. Rep OTAUpdateFile x -> OTAUpdateFile)
-> Generic OTAUpdateFile
forall x. Rep OTAUpdateFile x -> OTAUpdateFile
forall x. OTAUpdateFile -> Rep OTAUpdateFile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OTAUpdateFile x -> OTAUpdateFile
$cfrom :: forall x. OTAUpdateFile -> Rep OTAUpdateFile x
Prelude.Generic)

-- |
-- Create a value of 'OTAUpdateFile' 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:
--
-- 'fileLocation', 'oTAUpdateFile_fileLocation' - The location of the updated firmware.
--
-- 'fileType', 'oTAUpdateFile_fileType' - An integer value you can include in the job document to allow your
-- devices to identify the type of file received from the cloud.
--
-- 'fileVersion', 'oTAUpdateFile_fileVersion' - The file version.
--
-- 'attributes', 'oTAUpdateFile_attributes' - A list of name\/attribute pairs.
--
-- 'codeSigning', 'oTAUpdateFile_codeSigning' - The code signing method of the file.
--
-- 'fileName', 'oTAUpdateFile_fileName' - The name of the file.
newOTAUpdateFile ::
  OTAUpdateFile
newOTAUpdateFile :: OTAUpdateFile
newOTAUpdateFile =
  OTAUpdateFile' :: Maybe FileLocation
-> Maybe Natural
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe CodeSigning
-> Maybe Text
-> OTAUpdateFile
OTAUpdateFile'
    { $sel:fileLocation:OTAUpdateFile' :: Maybe FileLocation
fileLocation = Maybe FileLocation
forall a. Maybe a
Prelude.Nothing,
      $sel:fileType:OTAUpdateFile' :: Maybe Natural
fileType = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:fileVersion:OTAUpdateFile' :: Maybe Text
fileVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:attributes:OTAUpdateFile' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:codeSigning:OTAUpdateFile' :: Maybe CodeSigning
codeSigning = Maybe CodeSigning
forall a. Maybe a
Prelude.Nothing,
      $sel:fileName:OTAUpdateFile' :: Maybe Text
fileName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The location of the updated firmware.
oTAUpdateFile_fileLocation :: Lens.Lens' OTAUpdateFile (Prelude.Maybe FileLocation)
oTAUpdateFile_fileLocation :: (Maybe FileLocation -> f (Maybe FileLocation))
-> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_fileLocation = (OTAUpdateFile -> Maybe FileLocation)
-> (OTAUpdateFile -> Maybe FileLocation -> OTAUpdateFile)
-> Lens
     OTAUpdateFile
     OTAUpdateFile
     (Maybe FileLocation)
     (Maybe FileLocation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe FileLocation
fileLocation :: Maybe FileLocation
$sel:fileLocation:OTAUpdateFile' :: OTAUpdateFile -> Maybe FileLocation
fileLocation} -> Maybe FileLocation
fileLocation) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe FileLocation
a -> OTAUpdateFile
s {$sel:fileLocation:OTAUpdateFile' :: Maybe FileLocation
fileLocation = Maybe FileLocation
a} :: OTAUpdateFile)

-- | An integer value you can include in the job document to allow your
-- devices to identify the type of file received from the cloud.
oTAUpdateFile_fileType :: Lens.Lens' OTAUpdateFile (Prelude.Maybe Prelude.Natural)
oTAUpdateFile_fileType :: (Maybe Natural -> f (Maybe Natural))
-> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_fileType = (OTAUpdateFile -> Maybe Natural)
-> (OTAUpdateFile -> Maybe Natural -> OTAUpdateFile)
-> Lens OTAUpdateFile OTAUpdateFile (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe Natural
fileType :: Maybe Natural
$sel:fileType:OTAUpdateFile' :: OTAUpdateFile -> Maybe Natural
fileType} -> Maybe Natural
fileType) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe Natural
a -> OTAUpdateFile
s {$sel:fileType:OTAUpdateFile' :: Maybe Natural
fileType = Maybe Natural
a} :: OTAUpdateFile)

-- | The file version.
oTAUpdateFile_fileVersion :: Lens.Lens' OTAUpdateFile (Prelude.Maybe Prelude.Text)
oTAUpdateFile_fileVersion :: (Maybe Text -> f (Maybe Text)) -> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_fileVersion = (OTAUpdateFile -> Maybe Text)
-> (OTAUpdateFile -> Maybe Text -> OTAUpdateFile)
-> Lens OTAUpdateFile OTAUpdateFile (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe Text
fileVersion :: Maybe Text
$sel:fileVersion:OTAUpdateFile' :: OTAUpdateFile -> Maybe Text
fileVersion} -> Maybe Text
fileVersion) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe Text
a -> OTAUpdateFile
s {$sel:fileVersion:OTAUpdateFile' :: Maybe Text
fileVersion = Maybe Text
a} :: OTAUpdateFile)

-- | A list of name\/attribute pairs.
oTAUpdateFile_attributes :: Lens.Lens' OTAUpdateFile (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
oTAUpdateFile_attributes :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_attributes = (OTAUpdateFile -> Maybe (HashMap Text Text))
-> (OTAUpdateFile -> Maybe (HashMap Text Text) -> OTAUpdateFile)
-> Lens
     OTAUpdateFile
     OTAUpdateFile
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe (HashMap Text Text)
attributes :: Maybe (HashMap Text Text)
$sel:attributes:OTAUpdateFile' :: OTAUpdateFile -> Maybe (HashMap Text Text)
attributes} -> Maybe (HashMap Text Text)
attributes) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe (HashMap Text Text)
a -> OTAUpdateFile
s {$sel:attributes:OTAUpdateFile' :: Maybe (HashMap Text Text)
attributes = Maybe (HashMap Text Text)
a} :: OTAUpdateFile) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> OTAUpdateFile -> f OTAUpdateFile)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> OTAUpdateFile
-> f OTAUpdateFile
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The code signing method of the file.
oTAUpdateFile_codeSigning :: Lens.Lens' OTAUpdateFile (Prelude.Maybe CodeSigning)
oTAUpdateFile_codeSigning :: (Maybe CodeSigning -> f (Maybe CodeSigning))
-> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_codeSigning = (OTAUpdateFile -> Maybe CodeSigning)
-> (OTAUpdateFile -> Maybe CodeSigning -> OTAUpdateFile)
-> Lens
     OTAUpdateFile OTAUpdateFile (Maybe CodeSigning) (Maybe CodeSigning)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe CodeSigning
codeSigning :: Maybe CodeSigning
$sel:codeSigning:OTAUpdateFile' :: OTAUpdateFile -> Maybe CodeSigning
codeSigning} -> Maybe CodeSigning
codeSigning) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe CodeSigning
a -> OTAUpdateFile
s {$sel:codeSigning:OTAUpdateFile' :: Maybe CodeSigning
codeSigning = Maybe CodeSigning
a} :: OTAUpdateFile)

-- | The name of the file.
oTAUpdateFile_fileName :: Lens.Lens' OTAUpdateFile (Prelude.Maybe Prelude.Text)
oTAUpdateFile_fileName :: (Maybe Text -> f (Maybe Text)) -> OTAUpdateFile -> f OTAUpdateFile
oTAUpdateFile_fileName = (OTAUpdateFile -> Maybe Text)
-> (OTAUpdateFile -> Maybe Text -> OTAUpdateFile)
-> Lens OTAUpdateFile OTAUpdateFile (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OTAUpdateFile' {Maybe Text
fileName :: Maybe Text
$sel:fileName:OTAUpdateFile' :: OTAUpdateFile -> Maybe Text
fileName} -> Maybe Text
fileName) (\s :: OTAUpdateFile
s@OTAUpdateFile' {} Maybe Text
a -> OTAUpdateFile
s {$sel:fileName:OTAUpdateFile' :: Maybe Text
fileName = Maybe Text
a} :: OTAUpdateFile)

instance Core.FromJSON OTAUpdateFile where
  parseJSON :: Value -> Parser OTAUpdateFile
parseJSON =
    String
-> (Object -> Parser OTAUpdateFile)
-> Value
-> Parser OTAUpdateFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OTAUpdateFile"
      ( \Object
x ->
          Maybe FileLocation
-> Maybe Natural
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe CodeSigning
-> Maybe Text
-> OTAUpdateFile
OTAUpdateFile'
            (Maybe FileLocation
 -> Maybe Natural
 -> Maybe Text
 -> Maybe (HashMap Text Text)
 -> Maybe CodeSigning
 -> Maybe Text
 -> OTAUpdateFile)
-> Parser (Maybe FileLocation)
-> Parser
     (Maybe Natural
      -> Maybe Text
      -> Maybe (HashMap Text Text)
      -> Maybe CodeSigning
      -> Maybe Text
      -> OTAUpdateFile)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe FileLocation)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"fileLocation")
            Parser
  (Maybe Natural
   -> Maybe Text
   -> Maybe (HashMap Text Text)
   -> Maybe CodeSigning
   -> Maybe Text
   -> OTAUpdateFile)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Text
      -> Maybe (HashMap Text Text)
      -> Maybe CodeSigning
      -> Maybe Text
      -> OTAUpdateFile)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"fileType")
            Parser
  (Maybe Text
   -> Maybe (HashMap Text Text)
   -> Maybe CodeSigning
   -> Maybe Text
   -> OTAUpdateFile)
-> Parser (Maybe Text)
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe CodeSigning -> Maybe Text -> OTAUpdateFile)
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
"fileVersion")
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe CodeSigning -> Maybe Text -> OTAUpdateFile)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe CodeSigning -> Maybe Text -> OTAUpdateFile)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"attributes" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe CodeSigning -> Maybe Text -> OTAUpdateFile)
-> Parser (Maybe CodeSigning)
-> Parser (Maybe Text -> OTAUpdateFile)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CodeSigning)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"codeSigning")
            Parser (Maybe Text -> OTAUpdateFile)
-> Parser (Maybe Text) -> Parser OTAUpdateFile
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
"fileName")
      )

instance Prelude.Hashable OTAUpdateFile

instance Prelude.NFData OTAUpdateFile

instance Core.ToJSON OTAUpdateFile where
  toJSON :: OTAUpdateFile -> Value
toJSON OTAUpdateFile' {Maybe Natural
Maybe Text
Maybe (HashMap Text Text)
Maybe CodeSigning
Maybe FileLocation
fileName :: Maybe Text
codeSigning :: Maybe CodeSigning
attributes :: Maybe (HashMap Text Text)
fileVersion :: Maybe Text
fileType :: Maybe Natural
fileLocation :: Maybe FileLocation
$sel:fileName:OTAUpdateFile' :: OTAUpdateFile -> Maybe Text
$sel:codeSigning:OTAUpdateFile' :: OTAUpdateFile -> Maybe CodeSigning
$sel:attributes:OTAUpdateFile' :: OTAUpdateFile -> Maybe (HashMap Text Text)
$sel:fileVersion:OTAUpdateFile' :: OTAUpdateFile -> Maybe Text
$sel:fileType:OTAUpdateFile' :: OTAUpdateFile -> Maybe Natural
$sel:fileLocation:OTAUpdateFile' :: OTAUpdateFile -> Maybe FileLocation
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"fileLocation" Text -> FileLocation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (FileLocation -> Pair) -> Maybe FileLocation -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FileLocation
fileLocation,
            (Text
"fileType" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
fileType,
            (Text
"fileVersion" 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
fileVersion,
            (Text
"attributes" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
attributes,
            (Text
"codeSigning" Text -> CodeSigning -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (CodeSigning -> Pair) -> Maybe CodeSigning -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CodeSigning
codeSigning,
            (Text
"fileName" 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
fileName
          ]
      )