{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.DeviceFarm.CreateProject
-- 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)
--
-- Creates a project.
module Amazonka.DeviceFarm.CreateProject
  ( -- * Creating a Request
    CreateProject (..),
    newCreateProject,

    -- * Request Lenses
    createProject_defaultJobTimeoutMinutes,
    createProject_name,

    -- * Destructuring the Response
    CreateProjectResponse (..),
    newCreateProjectResponse,

    -- * Response Lenses
    createProjectResponse_project,
    createProjectResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DeviceFarm.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents a request to the create project operation.
--
-- /See:/ 'newCreateProject' smart constructor.
data CreateProject = CreateProject'
  { -- | Sets the execution timeout value (in minutes) for a project. All test
    -- runs in this project use the specified execution timeout value unless
    -- overridden when scheduling a run.
    CreateProject -> Maybe Int
defaultJobTimeoutMinutes :: Prelude.Maybe Prelude.Int,
    -- | The project\'s name.
    CreateProject -> Text
name :: Prelude.Text
  }
  deriving (CreateProject -> CreateProject -> Bool
(CreateProject -> CreateProject -> Bool)
-> (CreateProject -> CreateProject -> Bool) -> Eq CreateProject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateProject -> CreateProject -> Bool
$c/= :: CreateProject -> CreateProject -> Bool
== :: CreateProject -> CreateProject -> Bool
$c== :: CreateProject -> CreateProject -> Bool
Prelude.Eq, ReadPrec [CreateProject]
ReadPrec CreateProject
Int -> ReadS CreateProject
ReadS [CreateProject]
(Int -> ReadS CreateProject)
-> ReadS [CreateProject]
-> ReadPrec CreateProject
-> ReadPrec [CreateProject]
-> Read CreateProject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateProject]
$creadListPrec :: ReadPrec [CreateProject]
readPrec :: ReadPrec CreateProject
$creadPrec :: ReadPrec CreateProject
readList :: ReadS [CreateProject]
$creadList :: ReadS [CreateProject]
readsPrec :: Int -> ReadS CreateProject
$creadsPrec :: Int -> ReadS CreateProject
Prelude.Read, Int -> CreateProject -> ShowS
[CreateProject] -> ShowS
CreateProject -> String
(Int -> CreateProject -> ShowS)
-> (CreateProject -> String)
-> ([CreateProject] -> ShowS)
-> Show CreateProject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateProject] -> ShowS
$cshowList :: [CreateProject] -> ShowS
show :: CreateProject -> String
$cshow :: CreateProject -> String
showsPrec :: Int -> CreateProject -> ShowS
$cshowsPrec :: Int -> CreateProject -> ShowS
Prelude.Show, (forall x. CreateProject -> Rep CreateProject x)
-> (forall x. Rep CreateProject x -> CreateProject)
-> Generic CreateProject
forall x. Rep CreateProject x -> CreateProject
forall x. CreateProject -> Rep CreateProject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateProject x -> CreateProject
$cfrom :: forall x. CreateProject -> Rep CreateProject x
Prelude.Generic)

-- |
-- Create a value of 'CreateProject' 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:
--
-- 'defaultJobTimeoutMinutes', 'createProject_defaultJobTimeoutMinutes' - Sets the execution timeout value (in minutes) for a project. All test
-- runs in this project use the specified execution timeout value unless
-- overridden when scheduling a run.
--
-- 'name', 'createProject_name' - The project\'s name.
newCreateProject ::
  -- | 'name'
  Prelude.Text ->
  CreateProject
newCreateProject :: Text -> CreateProject
newCreateProject Text
pName_ =
  CreateProject' :: Maybe Int -> Text -> CreateProject
CreateProject'
    { $sel:defaultJobTimeoutMinutes:CreateProject' :: Maybe Int
defaultJobTimeoutMinutes =
        Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateProject' :: Text
name = Text
pName_
    }

-- | Sets the execution timeout value (in minutes) for a project. All test
-- runs in this project use the specified execution timeout value unless
-- overridden when scheduling a run.
createProject_defaultJobTimeoutMinutes :: Lens.Lens' CreateProject (Prelude.Maybe Prelude.Int)
createProject_defaultJobTimeoutMinutes :: (Maybe Int -> f (Maybe Int)) -> CreateProject -> f CreateProject
createProject_defaultJobTimeoutMinutes = (CreateProject -> Maybe Int)
-> (CreateProject -> Maybe Int -> CreateProject)
-> Lens CreateProject CreateProject (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateProject' {Maybe Int
defaultJobTimeoutMinutes :: Maybe Int
$sel:defaultJobTimeoutMinutes:CreateProject' :: CreateProject -> Maybe Int
defaultJobTimeoutMinutes} -> Maybe Int
defaultJobTimeoutMinutes) (\s :: CreateProject
s@CreateProject' {} Maybe Int
a -> CreateProject
s {$sel:defaultJobTimeoutMinutes:CreateProject' :: Maybe Int
defaultJobTimeoutMinutes = Maybe Int
a} :: CreateProject)

-- | The project\'s name.
createProject_name :: Lens.Lens' CreateProject Prelude.Text
createProject_name :: (Text -> f Text) -> CreateProject -> f CreateProject
createProject_name = (CreateProject -> Text)
-> (CreateProject -> Text -> CreateProject)
-> Lens CreateProject CreateProject Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateProject' {Text
name :: Text
$sel:name:CreateProject' :: CreateProject -> Text
name} -> Text
name) (\s :: CreateProject
s@CreateProject' {} Text
a -> CreateProject
s {$sel:name:CreateProject' :: Text
name = Text
a} :: CreateProject)

instance Core.AWSRequest CreateProject where
  type
    AWSResponse CreateProject =
      CreateProjectResponse
  request :: CreateProject -> Request CreateProject
request = Service -> CreateProject -> Request CreateProject
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateProject)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateProject))
-> Logger
-> Service
-> Proxy CreateProject
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateProject)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Project -> Int -> CreateProjectResponse
CreateProjectResponse'
            (Maybe Project -> Int -> CreateProjectResponse)
-> Either String (Maybe Project)
-> Either String (Int -> CreateProjectResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Project)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"project")
            Either String (Int -> CreateProjectResponse)
-> Either String Int -> Either String CreateProjectResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateProject

instance Prelude.NFData CreateProject

instance Core.ToHeaders CreateProject where
  toHeaders :: CreateProject -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateProject -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"DeviceFarm_20150623.CreateProject" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Core.ToPath CreateProject where
  toPath :: CreateProject -> ByteString
toPath = ByteString -> CreateProject -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreateProject where
  toQuery :: CreateProject -> QueryString
toQuery = QueryString -> CreateProject -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | Represents the result of a create project request.
--
-- /See:/ 'newCreateProjectResponse' smart constructor.
data CreateProjectResponse = CreateProjectResponse'
  { -- | The newly created project.
    CreateProjectResponse -> Maybe Project
project :: Prelude.Maybe Project,
    -- | The response's http status code.
    CreateProjectResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateProjectResponse -> CreateProjectResponse -> Bool
(CreateProjectResponse -> CreateProjectResponse -> Bool)
-> (CreateProjectResponse -> CreateProjectResponse -> Bool)
-> Eq CreateProjectResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateProjectResponse -> CreateProjectResponse -> Bool
$c/= :: CreateProjectResponse -> CreateProjectResponse -> Bool
== :: CreateProjectResponse -> CreateProjectResponse -> Bool
$c== :: CreateProjectResponse -> CreateProjectResponse -> Bool
Prelude.Eq, ReadPrec [CreateProjectResponse]
ReadPrec CreateProjectResponse
Int -> ReadS CreateProjectResponse
ReadS [CreateProjectResponse]
(Int -> ReadS CreateProjectResponse)
-> ReadS [CreateProjectResponse]
-> ReadPrec CreateProjectResponse
-> ReadPrec [CreateProjectResponse]
-> Read CreateProjectResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateProjectResponse]
$creadListPrec :: ReadPrec [CreateProjectResponse]
readPrec :: ReadPrec CreateProjectResponse
$creadPrec :: ReadPrec CreateProjectResponse
readList :: ReadS [CreateProjectResponse]
$creadList :: ReadS [CreateProjectResponse]
readsPrec :: Int -> ReadS CreateProjectResponse
$creadsPrec :: Int -> ReadS CreateProjectResponse
Prelude.Read, Int -> CreateProjectResponse -> ShowS
[CreateProjectResponse] -> ShowS
CreateProjectResponse -> String
(Int -> CreateProjectResponse -> ShowS)
-> (CreateProjectResponse -> String)
-> ([CreateProjectResponse] -> ShowS)
-> Show CreateProjectResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateProjectResponse] -> ShowS
$cshowList :: [CreateProjectResponse] -> ShowS
show :: CreateProjectResponse -> String
$cshow :: CreateProjectResponse -> String
showsPrec :: Int -> CreateProjectResponse -> ShowS
$cshowsPrec :: Int -> CreateProjectResponse -> ShowS
Prelude.Show, (forall x. CreateProjectResponse -> Rep CreateProjectResponse x)
-> (forall x. Rep CreateProjectResponse x -> CreateProjectResponse)
-> Generic CreateProjectResponse
forall x. Rep CreateProjectResponse x -> CreateProjectResponse
forall x. CreateProjectResponse -> Rep CreateProjectResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateProjectResponse x -> CreateProjectResponse
$cfrom :: forall x. CreateProjectResponse -> Rep CreateProjectResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateProjectResponse' 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:
--
-- 'project', 'createProjectResponse_project' - The newly created project.
--
-- 'httpStatus', 'createProjectResponse_httpStatus' - The response's http status code.
newCreateProjectResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateProjectResponse
newCreateProjectResponse :: Int -> CreateProjectResponse
newCreateProjectResponse Int
pHttpStatus_ =
  CreateProjectResponse' :: Maybe Project -> Int -> CreateProjectResponse
CreateProjectResponse'
    { $sel:project:CreateProjectResponse' :: Maybe Project
project = Maybe Project
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateProjectResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The newly created project.
createProjectResponse_project :: Lens.Lens' CreateProjectResponse (Prelude.Maybe Project)
createProjectResponse_project :: (Maybe Project -> f (Maybe Project))
-> CreateProjectResponse -> f CreateProjectResponse
createProjectResponse_project = (CreateProjectResponse -> Maybe Project)
-> (CreateProjectResponse
    -> Maybe Project -> CreateProjectResponse)
-> Lens
     CreateProjectResponse
     CreateProjectResponse
     (Maybe Project)
     (Maybe Project)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateProjectResponse' {Maybe Project
project :: Maybe Project
$sel:project:CreateProjectResponse' :: CreateProjectResponse -> Maybe Project
project} -> Maybe Project
project) (\s :: CreateProjectResponse
s@CreateProjectResponse' {} Maybe Project
a -> CreateProjectResponse
s {$sel:project:CreateProjectResponse' :: Maybe Project
project = Maybe Project
a} :: CreateProjectResponse)

-- | The response's http status code.
createProjectResponse_httpStatus :: Lens.Lens' CreateProjectResponse Prelude.Int
createProjectResponse_httpStatus :: (Int -> f Int) -> CreateProjectResponse -> f CreateProjectResponse
createProjectResponse_httpStatus = (CreateProjectResponse -> Int)
-> (CreateProjectResponse -> Int -> CreateProjectResponse)
-> Lens CreateProjectResponse CreateProjectResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateProjectResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateProjectResponse' :: CreateProjectResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateProjectResponse
s@CreateProjectResponse' {} Int
a -> CreateProjectResponse
s {$sel:httpStatus:CreateProjectResponse' :: Int
httpStatus = Int
a} :: CreateProjectResponse)

instance Prelude.NFData CreateProjectResponse