{-# 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.IoTSiteWise.Types.ImageFile
-- 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.IoTSiteWise.Types.ImageFile where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.ImageFileType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains an image file.
--
-- /See:/ 'newImageFile' smart constructor.
data ImageFile = ImageFile'
  { -- | The image file contents, represented as a base64-encoded string. The
    -- file size must be less than 1 MB.
    ImageFile -> Base64
data' :: Core.Base64,
    -- | The file type of the image.
    ImageFile -> ImageFileType
type' :: ImageFileType
  }
  deriving (ImageFile -> ImageFile -> Bool
(ImageFile -> ImageFile -> Bool)
-> (ImageFile -> ImageFile -> Bool) -> Eq ImageFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageFile -> ImageFile -> Bool
$c/= :: ImageFile -> ImageFile -> Bool
== :: ImageFile -> ImageFile -> Bool
$c== :: ImageFile -> ImageFile -> Bool
Prelude.Eq, ReadPrec [ImageFile]
ReadPrec ImageFile
Int -> ReadS ImageFile
ReadS [ImageFile]
(Int -> ReadS ImageFile)
-> ReadS [ImageFile]
-> ReadPrec ImageFile
-> ReadPrec [ImageFile]
-> Read ImageFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ImageFile]
$creadListPrec :: ReadPrec [ImageFile]
readPrec :: ReadPrec ImageFile
$creadPrec :: ReadPrec ImageFile
readList :: ReadS [ImageFile]
$creadList :: ReadS [ImageFile]
readsPrec :: Int -> ReadS ImageFile
$creadsPrec :: Int -> ReadS ImageFile
Prelude.Read, Int -> ImageFile -> ShowS
[ImageFile] -> ShowS
ImageFile -> String
(Int -> ImageFile -> ShowS)
-> (ImageFile -> String)
-> ([ImageFile] -> ShowS)
-> Show ImageFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageFile] -> ShowS
$cshowList :: [ImageFile] -> ShowS
show :: ImageFile -> String
$cshow :: ImageFile -> String
showsPrec :: Int -> ImageFile -> ShowS
$cshowsPrec :: Int -> ImageFile -> ShowS
Prelude.Show, (forall x. ImageFile -> Rep ImageFile x)
-> (forall x. Rep ImageFile x -> ImageFile) -> Generic ImageFile
forall x. Rep ImageFile x -> ImageFile
forall x. ImageFile -> Rep ImageFile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageFile x -> ImageFile
$cfrom :: forall x. ImageFile -> Rep ImageFile x
Prelude.Generic)

-- |
-- Create a value of 'ImageFile' 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:
--
-- 'data'', 'imageFile_data' - The image file contents, represented as a base64-encoded string. The
-- file size must be less than 1 MB.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'type'', 'imageFile_type' - The file type of the image.
newImageFile ::
  -- | 'data''
  Prelude.ByteString ->
  -- | 'type''
  ImageFileType ->
  ImageFile
newImageFile :: ByteString -> ImageFileType -> ImageFile
newImageFile ByteString
pData_ ImageFileType
pType_ =
  ImageFile' :: Base64 -> ImageFileType -> ImageFile
ImageFile'
    { $sel:data':ImageFile' :: Base64
data' = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> Base64
forall t b. AReview t b -> b -> t
Lens.# ByteString
pData_,
      $sel:type':ImageFile' :: ImageFileType
type' = ImageFileType
pType_
    }

-- | The image file contents, represented as a base64-encoded string. The
-- file size must be less than 1 MB.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
imageFile_data :: Lens.Lens' ImageFile Prelude.ByteString
imageFile_data :: (ByteString -> f ByteString) -> ImageFile -> f ImageFile
imageFile_data = (ImageFile -> Base64)
-> (ImageFile -> Base64 -> ImageFile)
-> Lens ImageFile ImageFile Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageFile' {Base64
data' :: Base64
$sel:data':ImageFile' :: ImageFile -> Base64
data'} -> Base64
data') (\s :: ImageFile
s@ImageFile' {} Base64
a -> ImageFile
s {$sel:data':ImageFile' :: Base64
data' = Base64
a} :: ImageFile) ((Base64 -> f Base64) -> ImageFile -> f ImageFile)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> ImageFile
-> f ImageFile
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

-- | The file type of the image.
imageFile_type :: Lens.Lens' ImageFile ImageFileType
imageFile_type :: (ImageFileType -> f ImageFileType) -> ImageFile -> f ImageFile
imageFile_type = (ImageFile -> ImageFileType)
-> (ImageFile -> ImageFileType -> ImageFile)
-> Lens ImageFile ImageFile ImageFileType ImageFileType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageFile' {ImageFileType
type' :: ImageFileType
$sel:type':ImageFile' :: ImageFile -> ImageFileType
type'} -> ImageFileType
type') (\s :: ImageFile
s@ImageFile' {} ImageFileType
a -> ImageFile
s {$sel:type':ImageFile' :: ImageFileType
type' = ImageFileType
a} :: ImageFile)

instance Prelude.Hashable ImageFile

instance Prelude.NFData ImageFile

instance Core.ToJSON ImageFile where
  toJSON :: ImageFile -> Value
toJSON ImageFile' {Base64
ImageFileType
type' :: ImageFileType
data' :: Base64
$sel:type':ImageFile' :: ImageFile -> ImageFileType
$sel:data':ImageFile' :: ImageFile -> Base64
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"data" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
data'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> ImageFileType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ImageFileType
type')
          ]
      )