{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE FlexibleInstances  #-}
{-# LANGUAGE NoImplicitPrelude  #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE TypeFamilies       #-}
{-# LANGUAGE TypeOperators      #-}

{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds      #-}
{-# OPTIONS_GHC -fno-warn-unused-imports    #-}

-- |
-- Module      : Network.Google.Resource.Spanner.Projects.Instances.SetIAMPolicy
-- Copyright   : (c) 2015-2016 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Sets the access control policy on an instance resource. Replaces any
-- existing policy. Authorization requires
-- \`spanner.instances.setIamPolicy\` on resource.
--
-- /See:/ <https://cloud.google.com/spanner/ Cloud Spanner API Reference> for @spanner.projects.instances.setIamPolicy@.
module Network.Google.Resource.Spanner.Projects.Instances.SetIAMPolicy
    (
    -- * REST Resource
      ProjectsInstancesSetIAMPolicyResource

    -- * Creating a Request
    , projectsInstancesSetIAMPolicy
    , ProjectsInstancesSetIAMPolicy

    -- * Request Lenses
    , pisipXgafv
    , pisipUploadProtocol
    , pisipAccessToken
    , pisipUploadType
    , pisipPayload
    , pisipResource
    , pisipCallback
    ) where

import           Network.Google.Prelude
import           Network.Google.Spanner.Types

-- | A resource alias for @spanner.projects.instances.setIamPolicy@ method which the
-- 'ProjectsInstancesSetIAMPolicy' request conforms to.
type ProjectsInstancesSetIAMPolicyResource =
     "v1" :>
       CaptureMode "resource" "setIamPolicy" Text :>
         QueryParam "$.xgafv" Xgafv :>
           QueryParam "upload_protocol" Text :>
             QueryParam "access_token" Text :>
               QueryParam "uploadType" Text :>
                 QueryParam "callback" Text :>
                   QueryParam "alt" AltJSON :>
                     ReqBody '[JSON] SetIAMPolicyRequest :>
                       Post '[JSON] Policy

-- | Sets the access control policy on an instance resource. Replaces any
-- existing policy. Authorization requires
-- \`spanner.instances.setIamPolicy\` on resource.
--
-- /See:/ 'projectsInstancesSetIAMPolicy' smart constructor.
data ProjectsInstancesSetIAMPolicy = ProjectsInstancesSetIAMPolicy'
    { _pisipXgafv          :: !(Maybe Xgafv)
    , _pisipUploadProtocol :: !(Maybe Text)
    , _pisipAccessToken    :: !(Maybe Text)
    , _pisipUploadType     :: !(Maybe Text)
    , _pisipPayload        :: !SetIAMPolicyRequest
    , _pisipResource       :: !Text
    , _pisipCallback       :: !(Maybe Text)
    } deriving (Eq,Show,Data,Typeable,Generic)

-- | Creates a value of 'ProjectsInstancesSetIAMPolicy' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'pisipXgafv'
--
-- * 'pisipUploadProtocol'
--
-- * 'pisipAccessToken'
--
-- * 'pisipUploadType'
--
-- * 'pisipPayload'
--
-- * 'pisipResource'
--
-- * 'pisipCallback'
projectsInstancesSetIAMPolicy
    :: SetIAMPolicyRequest -- ^ 'pisipPayload'
    -> Text -- ^ 'pisipResource'
    -> ProjectsInstancesSetIAMPolicy
projectsInstancesSetIAMPolicy pPisipPayload_ pPisipResource_ =
    ProjectsInstancesSetIAMPolicy'
    { _pisipXgafv = Nothing
    , _pisipUploadProtocol = Nothing
    , _pisipAccessToken = Nothing
    , _pisipUploadType = Nothing
    , _pisipPayload = pPisipPayload_
    , _pisipResource = pPisipResource_
    , _pisipCallback = Nothing
    }

-- | V1 error format.
pisipXgafv :: Lens' ProjectsInstancesSetIAMPolicy (Maybe Xgafv)
pisipXgafv
  = lens _pisipXgafv (\ s a -> s{_pisipXgafv = a})

-- | Upload protocol for media (e.g. \"raw\", \"multipart\").
pisipUploadProtocol :: Lens' ProjectsInstancesSetIAMPolicy (Maybe Text)
pisipUploadProtocol
  = lens _pisipUploadProtocol
      (\ s a -> s{_pisipUploadProtocol = a})

-- | OAuth access token.
pisipAccessToken :: Lens' ProjectsInstancesSetIAMPolicy (Maybe Text)
pisipAccessToken
  = lens _pisipAccessToken
      (\ s a -> s{_pisipAccessToken = a})

-- | Legacy upload protocol for media (e.g. \"media\", \"multipart\").
pisipUploadType :: Lens' ProjectsInstancesSetIAMPolicy (Maybe Text)
pisipUploadType
  = lens _pisipUploadType
      (\ s a -> s{_pisipUploadType = a})

-- | Multipart request metadata.
pisipPayload :: Lens' ProjectsInstancesSetIAMPolicy SetIAMPolicyRequest
pisipPayload
  = lens _pisipPayload (\ s a -> s{_pisipPayload = a})

-- | REQUIRED: The Cloud Spanner resource for which the policy is being set.
-- The format is \`projects\/\/instances\/\` for instance resources and
-- \`projects\/\/instances\/\/databases\/\` for databases resources.
pisipResource :: Lens' ProjectsInstancesSetIAMPolicy Text
pisipResource
  = lens _pisipResource
      (\ s a -> s{_pisipResource = a})

-- | JSONP
pisipCallback :: Lens' ProjectsInstancesSetIAMPolicy (Maybe Text)
pisipCallback
  = lens _pisipCallback
      (\ s a -> s{_pisipCallback = a})

instance GoogleRequest ProjectsInstancesSetIAMPolicy
         where
        type Rs ProjectsInstancesSetIAMPolicy = Policy
        type Scopes ProjectsInstancesSetIAMPolicy =
             '["https://www.googleapis.com/auth/cloud-platform",
               "https://www.googleapis.com/auth/spanner.admin"]
        requestClient ProjectsInstancesSetIAMPolicy'{..}
          = go _pisipResource _pisipXgafv _pisipUploadProtocol
              _pisipAccessToken
              _pisipUploadType
              _pisipCallback
              (Just AltJSON)
              _pisipPayload
              spannerService
          where go
                  = buildClient
                      (Proxy ::
                         Proxy ProjectsInstancesSetIAMPolicyResource)
                      mempty