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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.S3Location
import Amazonka.IoT.Types.Stream
import qualified Amazonka.Prelude as Prelude

-- | The location of the OTA update.
--
-- /See:/ 'newFileLocation' smart constructor.
data FileLocation = FileLocation'
  { -- | The location of the updated firmware in S3.
    FileLocation -> Maybe S3Location
s3Location :: Prelude.Maybe S3Location,
    -- | The stream that contains the OTA update.
    FileLocation -> Maybe Stream
stream :: Prelude.Maybe Stream
  }
  deriving (FileLocation -> FileLocation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileLocation -> FileLocation -> Bool
$c/= :: FileLocation -> FileLocation -> Bool
== :: FileLocation -> FileLocation -> Bool
$c== :: FileLocation -> FileLocation -> Bool
Prelude.Eq, ReadPrec [FileLocation]
ReadPrec FileLocation
Int -> ReadS FileLocation
ReadS [FileLocation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FileLocation]
$creadListPrec :: ReadPrec [FileLocation]
readPrec :: ReadPrec FileLocation
$creadPrec :: ReadPrec FileLocation
readList :: ReadS [FileLocation]
$creadList :: ReadS [FileLocation]
readsPrec :: Int -> ReadS FileLocation
$creadsPrec :: Int -> ReadS FileLocation
Prelude.Read, Int -> FileLocation -> ShowS
[FileLocation] -> ShowS
FileLocation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileLocation] -> ShowS
$cshowList :: [FileLocation] -> ShowS
show :: FileLocation -> String
$cshow :: FileLocation -> String
showsPrec :: Int -> FileLocation -> ShowS
$cshowsPrec :: Int -> FileLocation -> ShowS
Prelude.Show, forall x. Rep FileLocation x -> FileLocation
forall x. FileLocation -> Rep FileLocation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FileLocation x -> FileLocation
$cfrom :: forall x. FileLocation -> Rep FileLocation x
Prelude.Generic)

-- |
-- Create a value of 'FileLocation' 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:
--
-- 's3Location', 'fileLocation_s3Location' - The location of the updated firmware in S3.
--
-- 'stream', 'fileLocation_stream' - The stream that contains the OTA update.
newFileLocation ::
  FileLocation
newFileLocation :: FileLocation
newFileLocation =
  FileLocation'
    { $sel:s3Location:FileLocation' :: Maybe S3Location
s3Location = forall a. Maybe a
Prelude.Nothing,
      $sel:stream:FileLocation' :: Maybe Stream
stream = forall a. Maybe a
Prelude.Nothing
    }

-- | The location of the updated firmware in S3.
fileLocation_s3Location :: Lens.Lens' FileLocation (Prelude.Maybe S3Location)
fileLocation_s3Location :: Lens' FileLocation (Maybe S3Location)
fileLocation_s3Location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileLocation' {Maybe S3Location
s3Location :: Maybe S3Location
$sel:s3Location:FileLocation' :: FileLocation -> Maybe S3Location
s3Location} -> Maybe S3Location
s3Location) (\s :: FileLocation
s@FileLocation' {} Maybe S3Location
a -> FileLocation
s {$sel:s3Location:FileLocation' :: Maybe S3Location
s3Location = Maybe S3Location
a} :: FileLocation)

-- | The stream that contains the OTA update.
fileLocation_stream :: Lens.Lens' FileLocation (Prelude.Maybe Stream)
fileLocation_stream :: Lens' FileLocation (Maybe Stream)
fileLocation_stream = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FileLocation' {Maybe Stream
stream :: Maybe Stream
$sel:stream:FileLocation' :: FileLocation -> Maybe Stream
stream} -> Maybe Stream
stream) (\s :: FileLocation
s@FileLocation' {} Maybe Stream
a -> FileLocation
s {$sel:stream:FileLocation' :: Maybe Stream
stream = Maybe Stream
a} :: FileLocation)

instance Data.FromJSON FileLocation where
  parseJSON :: Value -> Parser FileLocation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FileLocation"
      ( \Object
x ->
          Maybe S3Location -> Maybe Stream -> FileLocation
FileLocation'
            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
"s3Location")
            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
"stream")
      )

instance Prelude.Hashable FileLocation where
  hashWithSalt :: Int -> FileLocation -> Int
hashWithSalt Int
_salt FileLocation' {Maybe S3Location
Maybe Stream
stream :: Maybe Stream
s3Location :: Maybe S3Location
$sel:stream:FileLocation' :: FileLocation -> Maybe Stream
$sel:s3Location:FileLocation' :: FileLocation -> Maybe S3Location
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe S3Location
s3Location
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Stream
stream

instance Prelude.NFData FileLocation where
  rnf :: FileLocation -> ()
rnf FileLocation' {Maybe S3Location
Maybe Stream
stream :: Maybe Stream
s3Location :: Maybe S3Location
$sel:stream:FileLocation' :: FileLocation -> Maybe Stream
$sel:s3Location:FileLocation' :: FileLocation -> Maybe S3Location
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe S3Location
s3Location
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Stream
stream

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