# Copyright (c) 2021-Present (Prashanth Pradeep)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import requests as re
import infapy
from infapy.exceptions import InvalidDetailsProvided

class AgentService():
    def __init__(self,v3,v3BaseURL,v3SessionID):
        self._v3 = v3
        self._v3BaseURL = v3BaseURL
        self._v3SessionID = v3SessionID
    
    def updateAgentService(self,serviceName, serviceAction, agentId):
        url=self._v3BaseURL + "/public/core/v3/agent/service"
        headers = {'Content-Type': "application/json", 'Accept': "application/json","INFA-SESSION-ID":self._v3SessionID}
        body = {
            'serviceName':serviceName,
            'serviceAction':serviceAction,
            'agentId':agentId}

        infapy.log.info("agentService API URL - " + url)
        infapy.log.info("API Headers: " + str(headers))
        infapy.log.info("Body: " + str(body))

        try:
            response = re.post(url=url, json=body, headers=headers)
            data = response.json()
            infapy.log.debug(str(data))
            try:
                if ("error" in data):
                    infapy.log.error("Please validate the details passed")
                    infapy.log.error(str(data))
                    raise InvalidDetailsProvided
            except Exception as e:
                infapy.log.exception(e)
                raise
        except Exception as e:
            infapy.log.exception(e)
            raise
        infapy.log.info(data["message"])    
        return data
[((33, 8, 33, 56), 'infapy.log.info', 'infapy.log.info', ({(33, 24, 33, 55): "('agentService API URL - ' + url)"}, {}), "('agentService API URL - ' + url)", False, 'import infapy\n'), ((52, 8, 52, 40), 'infapy.log.info', 'infapy.log.info', ({(52, 24, 52, 39): "data['message']"}, {}), "(data['message'])", False, 'import infapy\n'), ((38, 23, 38, 67), 'requests.post', 're.post', (), '', True, 'import requests as re\n'), ((50, 12, 50, 35), 'infapy.log.exception', 'infapy.log.exception', ({(50, 33, 50, 34): 'e'}, {}), '(e)', False, 'import infapy\n'), ((43, 20, 43, 74), 'infapy.log.error', 'infapy.log.error', ({(43, 37, 43, 73): '"""Please validate the details passed"""'}, {}), "('Please validate the details passed')", False, 'import infapy\n'), ((47, 16, 47, 39), 'infapy.log.exception', 'infapy.log.exception', ({(47, 37, 47, 38): 'e'}, {}), '(e)', False, 'import infapy\n')]