{-# LANGUAGE DataKinds                   #-}
{-# LANGUAGE DeriveGeneric               #-}
{-# LANGUAGE FlexibleInstances           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving  #-}
{-# LANGUAGE LambdaCase                  #-}
{-# LANGUAGE NoImplicitPrelude           #-}
{-# LANGUAGE OverloadedStrings           #-}
{-# LANGUAGE RecordWildCards             #-}
{-# LANGUAGE TypeFamilies                #-}

{-# OPTIONS_GHC -fno-warn-unused-imports #-}

-- Module      : Network.AWS.DataPipeline.ValidatePipelineDefinition
-- Copyright   : (c) 2013-2014 Brendan Hay <brendan.g.hay@gmail.com>
-- License     : This Source Code Form is subject to the terms of
--               the Mozilla Public License, v. 2.0.
--               A copy of the MPL can be found in the LICENSE file or
--               you can obtain it at http://mozilla.org/MPL/2.0/.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
--
-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- | Validates the specified pipeline definition to ensure that it is well formed
-- and can be run without error.
--
-- <http://docs.aws.amazon.com/datapipeline/latest/APIReference/API_ValidatePipelineDefinition.html>
module Network.AWS.DataPipeline.ValidatePipelineDefinition
    (
    -- * Request
      ValidatePipelineDefinition
    -- ** Request constructor
    , validatePipelineDefinition
    -- ** Request lenses
    , vpdParameterObjects
    , vpdParameterValues
    , vpdPipelineId
    , vpdPipelineObjects

    -- * Response
    , ValidatePipelineDefinitionResponse
    -- ** Response constructor
    , validatePipelineDefinitionResponse
    -- ** Response lenses
    , vpdrErrored
    , vpdrValidationErrors
    , vpdrValidationWarnings
    ) where

import Network.AWS.Data (Object)
import Network.AWS.Prelude
import Network.AWS.Request.JSON
import Network.AWS.DataPipeline.Types
import qualified GHC.Exts

data ValidatePipelineDefinition = ValidatePipelineDefinition
    { _vpdParameterObjects :: List "parameterObjects" ParameterObject
    , _vpdParameterValues  :: List "parameterValues" ParameterValue
    , _vpdPipelineId       :: Text
    , _vpdPipelineObjects  :: List "pipelineObjects" PipelineObject
    } deriving (Eq, Read, Show)

-- | 'ValidatePipelineDefinition' constructor.
--
-- The fields accessible through corresponding lenses are:
--
-- * 'vpdParameterObjects' @::@ ['ParameterObject']
--
-- * 'vpdParameterValues' @::@ ['ParameterValue']
--
-- * 'vpdPipelineId' @::@ 'Text'
--
-- * 'vpdPipelineObjects' @::@ ['PipelineObject']
--
validatePipelineDefinition :: Text -- ^ 'vpdPipelineId'
                           -> ValidatePipelineDefinition
validatePipelineDefinition p1 = ValidatePipelineDefinition
    { _vpdPipelineId       = p1
    , _vpdPipelineObjects  = mempty
    , _vpdParameterObjects = mempty
    , _vpdParameterValues  = mempty
    }

-- | The parameter objects used with the pipeline.
vpdParameterObjects :: Lens' ValidatePipelineDefinition [ParameterObject]
vpdParameterObjects =
    lens _vpdParameterObjects (\s a -> s { _vpdParameterObjects = a })
        . _List

-- | The parameter values used with the pipeline.
vpdParameterValues :: Lens' ValidatePipelineDefinition [ParameterValue]
vpdParameterValues =
    lens _vpdParameterValues (\s a -> s { _vpdParameterValues = a })
        . _List

-- | The ID of the pipeline.
vpdPipelineId :: Lens' ValidatePipelineDefinition Text
vpdPipelineId = lens _vpdPipelineId (\s a -> s { _vpdPipelineId = a })

-- | The objects that define the pipeline changes to validate against the pipeline.
vpdPipelineObjects :: Lens' ValidatePipelineDefinition [PipelineObject]
vpdPipelineObjects =
    lens _vpdPipelineObjects (\s a -> s { _vpdPipelineObjects = a })
        . _List

data ValidatePipelineDefinitionResponse = ValidatePipelineDefinitionResponse
    { _vpdrErrored            :: Bool
    , _vpdrValidationErrors   :: List "validationErrors" ValidationError
    , _vpdrValidationWarnings :: List "validationWarnings" ValidationWarning
    } deriving (Eq, Read, Show)

-- | 'ValidatePipelineDefinitionResponse' constructor.
--
-- The fields accessible through corresponding lenses are:
--
-- * 'vpdrErrored' @::@ 'Bool'
--
-- * 'vpdrValidationErrors' @::@ ['ValidationError']
--
-- * 'vpdrValidationWarnings' @::@ ['ValidationWarning']
--
validatePipelineDefinitionResponse :: Bool -- ^ 'vpdrErrored'
                                   -> ValidatePipelineDefinitionResponse
validatePipelineDefinitionResponse p1 = ValidatePipelineDefinitionResponse
    { _vpdrErrored            = p1
    , _vpdrValidationErrors   = mempty
    , _vpdrValidationWarnings = mempty
    }

-- | Indicates whether there were validation errors.
vpdrErrored :: Lens' ValidatePipelineDefinitionResponse Bool
vpdrErrored = lens _vpdrErrored (\s a -> s { _vpdrErrored = a })

-- | Any validation errors that were found.
vpdrValidationErrors :: Lens' ValidatePipelineDefinitionResponse [ValidationError]
vpdrValidationErrors =
    lens _vpdrValidationErrors (\s a -> s { _vpdrValidationErrors = a })
        . _List

-- | Any validation warnings that were found.
vpdrValidationWarnings :: Lens' ValidatePipelineDefinitionResponse [ValidationWarning]
vpdrValidationWarnings =
    lens _vpdrValidationWarnings (\s a -> s { _vpdrValidationWarnings = a })
        . _List

instance ToPath ValidatePipelineDefinition where
    toPath = const "/"

instance ToQuery ValidatePipelineDefinition where
    toQuery = const mempty

instance ToHeaders ValidatePipelineDefinition

instance ToJSON ValidatePipelineDefinition where
    toJSON ValidatePipelineDefinition{..} = object
        [ "pipelineId"       .= _vpdPipelineId
        , "pipelineObjects"  .= _vpdPipelineObjects
        , "parameterObjects" .= _vpdParameterObjects
        , "parameterValues"  .= _vpdParameterValues
        ]

instance AWSRequest ValidatePipelineDefinition where
    type Sv ValidatePipelineDefinition = DataPipeline
    type Rs ValidatePipelineDefinition = ValidatePipelineDefinitionResponse

    request  = post "ValidatePipelineDefinition"
    response = jsonResponse

instance FromJSON ValidatePipelineDefinitionResponse where
    parseJSON = withObject "ValidatePipelineDefinitionResponse" $ \o -> ValidatePipelineDefinitionResponse
        <$> o .:  "errored"
        <*> o .:? "validationErrors" .!= mempty
        <*> o .:? "validationWarnings" .!= mempty
