{-# 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.SMS.Types.UserData
-- 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.SMS.Types.UserData where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SMS.Types.S3Location

-- | A script that runs on first launch of an Amazon EC2 instance. Used for
-- configuring the server during launch.
--
-- /See:/ 'newUserData' smart constructor.
data UserData = UserData'
  { -- | Amazon S3 location of the user-data script.
    UserData -> Maybe S3Location
s3Location :: Prelude.Maybe S3Location
  }
  deriving (UserData -> UserData -> Bool
(UserData -> UserData -> Bool)
-> (UserData -> UserData -> Bool) -> Eq UserData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserData -> UserData -> Bool
$c/= :: UserData -> UserData -> Bool
== :: UserData -> UserData -> Bool
$c== :: UserData -> UserData -> Bool
Prelude.Eq, ReadPrec [UserData]
ReadPrec UserData
Int -> ReadS UserData
ReadS [UserData]
(Int -> ReadS UserData)
-> ReadS [UserData]
-> ReadPrec UserData
-> ReadPrec [UserData]
-> Read UserData
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserData]
$creadListPrec :: ReadPrec [UserData]
readPrec :: ReadPrec UserData
$creadPrec :: ReadPrec UserData
readList :: ReadS [UserData]
$creadList :: ReadS [UserData]
readsPrec :: Int -> ReadS UserData
$creadsPrec :: Int -> ReadS UserData
Prelude.Read, Int -> UserData -> ShowS
[UserData] -> ShowS
UserData -> String
(Int -> UserData -> ShowS)
-> (UserData -> String) -> ([UserData] -> ShowS) -> Show UserData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserData] -> ShowS
$cshowList :: [UserData] -> ShowS
show :: UserData -> String
$cshow :: UserData -> String
showsPrec :: Int -> UserData -> ShowS
$cshowsPrec :: Int -> UserData -> ShowS
Prelude.Show, (forall x. UserData -> Rep UserData x)
-> (forall x. Rep UserData x -> UserData) -> Generic UserData
forall x. Rep UserData x -> UserData
forall x. UserData -> Rep UserData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UserData x -> UserData
$cfrom :: forall x. UserData -> Rep UserData x
Prelude.Generic)

-- |
-- Create a value of 'UserData' 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', 'userData_s3Location' - Amazon S3 location of the user-data script.
newUserData ::
  UserData
newUserData :: UserData
newUserData = UserData' :: Maybe S3Location -> UserData
UserData' {$sel:s3Location:UserData' :: Maybe S3Location
s3Location = Maybe S3Location
forall a. Maybe a
Prelude.Nothing}

-- | Amazon S3 location of the user-data script.
userData_s3Location :: Lens.Lens' UserData (Prelude.Maybe S3Location)
userData_s3Location :: (Maybe S3Location -> f (Maybe S3Location))
-> UserData -> f UserData
userData_s3Location = (UserData -> Maybe S3Location)
-> (UserData -> Maybe S3Location -> UserData)
-> Lens UserData UserData (Maybe S3Location) (Maybe S3Location)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UserData' {Maybe S3Location
s3Location :: Maybe S3Location
$sel:s3Location:UserData' :: UserData -> Maybe S3Location
s3Location} -> Maybe S3Location
s3Location) (\s :: UserData
s@UserData' {} Maybe S3Location
a -> UserData
s {$sel:s3Location:UserData' :: Maybe S3Location
s3Location = Maybe S3Location
a} :: UserData)

instance Core.FromJSON UserData where
  parseJSON :: Value -> Parser UserData
parseJSON =
    String -> (Object -> Parser UserData) -> Value -> Parser UserData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"UserData"
      ( \Object
x ->
          Maybe S3Location -> UserData
UserData' (Maybe S3Location -> UserData)
-> Parser (Maybe S3Location) -> Parser UserData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe S3Location)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"s3Location")
      )

instance Prelude.Hashable UserData

instance Prelude.NFData UserData

instance Core.ToJSON UserData where
  toJSON :: UserData -> Value
toJSON UserData' {Maybe S3Location
s3Location :: Maybe S3Location
$sel:s3Location:UserData' :: UserData -> Maybe S3Location
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"s3Location" Text -> S3Location -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (S3Location -> Pair) -> Maybe S3Location -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe S3Location
s3Location]
      )