#!/usr/bin/env python
"""
The MIT License (MIT)

Copyright (c) 2017 LeanIX GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
"""
import sys
import os

from models import *


class DocumentsApi(object):

    def __init__(self, apiClient):
      self.apiClient = apiClient

    

    def getDocuments(self, **kwargs):
        """
        Read all documents

        Args:
            relations, bool: If set to true, all relations of the Fact Sheet are fetched as well. Fetching all relations can be slower. Default: false. (optional)

            filter, str: Full-text filter (optional)

            referenceSystem, str: Reference system filter, e.g. Signavio (optional)

            referenceID, str: ReferenceID, e.g. Signavio ID (optional)

            factSheetID, str: FactSheetID, e.g. LeanIX ID (optional)

            

        Returns: Array[Document]
        """

        allParams = ['relations', 'filter', 'referenceSystem', 'referenceID', 'factSheetID']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method getDocuments" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'GET'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if ('relations' in params):
            queryParams['relations'] = self.apiClient.toPathValue(params['relations'])
        if ('filter' in params):
            queryParams['filter'] = self.apiClient.toPathValue(params['filter'])
        if ('referenceSystem' in params):
            queryParams['referenceSystem'] = self.apiClient.toPathValue(params['referenceSystem'])
        if ('referenceID' in params):
            queryParams['referenceID'] = self.apiClient.toPathValue(params['referenceID'])
        if ('factSheetID' in params):
            queryParams['factSheetID'] = self.apiClient.toPathValue(params['factSheetID'])
        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        if not response:
            return None

        responseObject = self.apiClient.deserialize(response, 'Array[Document]')
        return responseObject
        

        

    def createDocument(self, **kwargs):
        """
        Create a new Document

        Args:
            body, Document: Message-Body (optional)

            

        Returns: Document
        """

        allParams = ['body']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method createDocument" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'POST'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        if ('' in params):
            bodyParam = params['']
        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        if not response:
            return None

        responseObject = self.apiClient.deserialize(response, 'Document')
        return responseObject
        

        

    def getDocument(self, ID, **kwargs):
        """
        Read a Document by a given ID

        Args:
            ID, str: Unique ID (required)

            relations, bool: If set to true, all relations of the Fact Sheet are fetched as well. Fetching all relations can be slower. Default: false. (optional)

            

        Returns: Document
        """

        allParams = ['ID', 'relations']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method getDocument" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents/{ID}'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'GET'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if ('relations' in params):
            queryParams['relations'] = self.apiClient.toPathValue(params['relations'])
        if ('ID' in params):
            replacement = str(self.apiClient.toPathValue(params['ID']))
            resourcePath = resourcePath.replace('{' + 'ID' + '}',
                                                replacement)
        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        if not response:
            return None

        responseObject = self.apiClient.deserialize(response, 'Document')
        return responseObject
        

        

    def updateDocument(self, ID, **kwargs):
        """
        Update a Document by a given ID

        Args:
            ID, str: Unique ID (required)

            body, Document: Message-Body (optional)

            

        Returns: Document
        """

        allParams = ['ID', 'body']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method updateDocument" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents/{ID}'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'PUT'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if ('ID' in params):
            replacement = str(self.apiClient.toPathValue(params['ID']))
            resourcePath = resourcePath.replace('{' + 'ID' + '}',
                                                replacement)
        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        if ('' in params):
            bodyParam = params['']
        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        if not response:
            return None

        responseObject = self.apiClient.deserialize(response, 'Document')
        return responseObject
        

        

    def deleteDocument(self, ID, **kwargs):
        """
        Delete a Document by a given ID

        Args:
            ID, str: Unique ID (required)

            

        Returns: 
        """

        allParams = ['ID']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method deleteDocument" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents/{ID}'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'DELETE'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if ('ID' in params):
            replacement = str(self.apiClient.toPathValue(params['ID']))
            resourcePath = resourcePath.replace('{' + 'ID' + '}',
                                                replacement)
        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        

        

    def updateDataObject(self, ID, **kwargs):
        """
        Update the data object for the given document ID

        Args:
            ID, str: Unique ID (required)

            body, DataObject: Message-Body (optional)

            

        Returns: DataObject
        """

        allParams = ['ID', 'body']

        params = locals()
        for (key, val) in params['kwargs'].iteritems():
            if key not in allParams:
                raise TypeError("Got an unexpected keyword argument '%s' to method updateDataObject" % key)
            params[key] = val
        del params['kwargs']

        resourcePath = '/documents/{ID}/dataobjects'
        resourcePath = resourcePath.replace('{format}', 'json')
        method = 'PUT'

        queryParams = {}
        headerParams = {}
        formParams = {}
        bodyParam = None

        if ('ID' in params):
            replacement = str(self.apiClient.toPathValue(params['ID']))
            resourcePath = resourcePath.replace('{' + 'ID' + '}',
                                                replacement)
        if formParams:
            headerParams['Content-type'] = 'application/x-www-form-urlencoded'

        if ('' in params):
            bodyParam = params['']
        # postData = (formParams if formParams else bodyParam)
        postData = params['body'] if 'body' in params else None

        response = self.apiClient.callAPI(resourcePath, method, queryParams,
                                          postData, headerParams)

        if not response:
            return None

        responseObject = self.apiClient.deserialize(response, 'DataObject')
        return responseObject
        

        

    




