{-# 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.Support.Types.Attachment
-- 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.Support.Types.Attachment where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An attachment to a case communication. The attachment consists of the
-- file name and the content of the file.
--
-- /See:/ 'newAttachment' smart constructor.
data Attachment = Attachment'
  { -- | The content of the attachment file.
    Attachment -> Maybe Base64
data' :: Prelude.Maybe Core.Base64,
    -- | The name of the attachment file.
    Attachment -> Maybe Text
fileName :: Prelude.Maybe Prelude.Text
  }
  deriving (Attachment -> Attachment -> Bool
(Attachment -> Attachment -> Bool)
-> (Attachment -> Attachment -> Bool) -> Eq Attachment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attachment -> Attachment -> Bool
$c/= :: Attachment -> Attachment -> Bool
== :: Attachment -> Attachment -> Bool
$c== :: Attachment -> Attachment -> Bool
Prelude.Eq, ReadPrec [Attachment]
ReadPrec Attachment
Int -> ReadS Attachment
ReadS [Attachment]
(Int -> ReadS Attachment)
-> ReadS [Attachment]
-> ReadPrec Attachment
-> ReadPrec [Attachment]
-> Read Attachment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Attachment]
$creadListPrec :: ReadPrec [Attachment]
readPrec :: ReadPrec Attachment
$creadPrec :: ReadPrec Attachment
readList :: ReadS [Attachment]
$creadList :: ReadS [Attachment]
readsPrec :: Int -> ReadS Attachment
$creadsPrec :: Int -> ReadS Attachment
Prelude.Read, Int -> Attachment -> ShowS
[Attachment] -> ShowS
Attachment -> String
(Int -> Attachment -> ShowS)
-> (Attachment -> String)
-> ([Attachment] -> ShowS)
-> Show Attachment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attachment] -> ShowS
$cshowList :: [Attachment] -> ShowS
show :: Attachment -> String
$cshow :: Attachment -> String
showsPrec :: Int -> Attachment -> ShowS
$cshowsPrec :: Int -> Attachment -> ShowS
Prelude.Show, (forall x. Attachment -> Rep Attachment x)
-> (forall x. Rep Attachment x -> Attachment) -> Generic Attachment
forall x. Rep Attachment x -> Attachment
forall x. Attachment -> Rep Attachment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Attachment x -> Attachment
$cfrom :: forall x. Attachment -> Rep Attachment x
Prelude.Generic)

-- |
-- Create a value of 'Attachment' 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'', 'attachment_data' - The content of the attachment file.--
-- -- /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.
--
-- 'fileName', 'attachment_fileName' - The name of the attachment file.
newAttachment ::
  Attachment
newAttachment :: Attachment
newAttachment =
  Attachment' :: Maybe Base64 -> Maybe Text -> Attachment
Attachment'
    { $sel:data':Attachment' :: Maybe Base64
data' = Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:fileName:Attachment' :: Maybe Text
fileName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The content of the attachment file.--
-- -- /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.
attachment_data :: Lens.Lens' Attachment (Prelude.Maybe Prelude.ByteString)
attachment_data :: (Maybe ByteString -> f (Maybe ByteString))
-> Attachment -> f Attachment
attachment_data = (Attachment -> Maybe Base64)
-> (Attachment -> Maybe Base64 -> Attachment)
-> Lens Attachment Attachment (Maybe Base64) (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Attachment' {Maybe Base64
data' :: Maybe Base64
$sel:data':Attachment' :: Attachment -> Maybe Base64
data'} -> Maybe Base64
data') (\s :: Attachment
s@Attachment' {} Maybe Base64
a -> Attachment
s {$sel:data':Attachment' :: Maybe Base64
data' = Maybe Base64
a} :: Attachment) ((Maybe Base64 -> f (Maybe Base64)) -> Attachment -> f Attachment)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> Attachment
-> f Attachment
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
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 Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

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

instance Core.FromJSON Attachment where
  parseJSON :: Value -> Parser Attachment
parseJSON =
    String
-> (Object -> Parser Attachment) -> Value -> Parser Attachment
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Attachment"
      ( \Object
x ->
          Maybe Base64 -> Maybe Text -> Attachment
Attachment'
            (Maybe Base64 -> Maybe Text -> Attachment)
-> Parser (Maybe Base64) -> Parser (Maybe Text -> Attachment)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Base64)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"data")
            Parser (Maybe Text -> Attachment)
-> Parser (Maybe Text) -> Parser Attachment
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 Attachment

instance Prelude.NFData Attachment

instance Core.ToJSON Attachment where
  toJSON :: Attachment -> Value
toJSON Attachment' {Maybe Text
Maybe Base64
fileName :: Maybe Text
data' :: Maybe Base64
$sel:fileName:Attachment' :: Attachment -> Maybe Text
$sel:data':Attachment' :: Attachment -> Maybe Base64
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"data" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Base64 -> Pair) -> Maybe Base64 -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Base64
data',
            (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
          ]
      )