# Path: api/facial/FacialEngine.py
# class FacialEngine:
# 
#     name = "Base Facial Engine"
#     apiKey = ""
# 
#     # Load the image repository into the engine (aka API service)
#     # type - protocol to use (eg. ftp, http, file, etc)
#     # uri - the location to the data. If file, then the uri would be relative path to the files
#     def loadRepo(self,type, uri): 
#         return true
# 
#     # Search for a facial match based on the image provided by the uri parameter
#     # type - file or http
#     # uri - the location of the file (eg. facialimages/dpd/search/fer2a24s.jpg)
#     def search(self,type, uri):  
#         return true
# 
#     # Callback function that should be used for long running API's
#     def searchCallBack(self):
#         return true
# 
#     # Set the API Key that should be used for accessing the facial API
#     # apiKey - the API key for the facial API
#     def setAPIKey(self,apiKey):
#         self.apiKey = apiKey  
# 
#     # Returns the name of the engine
#     def getName(self):
#         return self.name
#     
#     # Returns the API Key 
#     def getAPIKey(self):
#         return self.apiKey


from .FacialEngine import FacialEngine
from api import *
from  api.sql.models import *
import http.client, urllib.request, urllib.parse, urllib.error, base64
import json, requests
import os,sys
                'Ocp-Apim-Subscription-Key' : self.getAPIKey(),
                'Content-Type' : 'application/json',
            }
   
            params = urllib.parse.urlencode({
            })

            try:
            
                fullURL = "https://" + hostname + url
                print(fullURL)
                response = requests.request(action,fullURL,json=body,headers=_headers)
            #    conn = http.client.HTTPSConnection(self.hostname)
            #    if (body == None):
            #        conn.request(action, url,headers= _headers)
            #    else:
            #        conn.request(action, url,body,_headers)
            #        print("Finished request with body")
            #    response = conn.getresponse()
            #    #data = str(response.read())
            #    data = response.read().decode('utf8')
            #    conn.close()
            except Exception as e:
                  print("[Errno {0}] {1}".format(e.errno, e.strerror)) 
                  result['code'] = 404
                  result['response'] = data
                  return result
            if response.status_code in (200, 202):
                  result['code'] = response.status_code
                  result['response'] = response.text

# Path: api/facial/FacialEngine.py
# class FacialEngine:
# 
#     name = "Base Facial Engine"
#     apiKey = ""
# 
#     # Load the image repository into the engine (aka API service)
#     # type - protocol to use (eg. ftp, http, file, etc)
#     # uri - the location to the data. If file, then the uri would be relative path to the files
#     def loadRepo(self,type, uri): 
#         return true
# 
#     # Search for a facial match based on the image provided by the uri parameter
#     # type - file or http
#     # uri - the location of the file (eg. facialimages/dpd/search/fer2a24s.jpg)
#     def search(self,type, uri):  
#         return true
# 
#     # Callback function that should be used for long running API's
#     def searchCallBack(self):
#         return true
# 
#     # Set the API Key that should be used for accessing the facial API
#     # apiKey - the API key for the facial API
#     def setAPIKey(self,apiKey):
#         self.apiKey = apiKey  
# 
#     # Returns the name of the engine
#     def getName(self):
#         return self.name
#     
#     # Returns the API Key 
#     def getAPIKey(self):
#         return self.apiKey


# Path: api/facial/MSFTFacialEngine.py
from .FacialEngine import FacialEngine
from api import *
from  api.sql.models import *
import http.client, urllib.request, urllib.parse, urllib.error, base64
import json, requests
import os,sys

                'Ocp-Apim-Subscription-Key' : self.getAPIKey(),
                'Content-Type' : 'application/json',
            }
   
            params = urllib.parse.urlencode({
            })

            try:
            
                fullURL = "https://" + hostname + url
                print(fullURL)
                response = requests.request(action,fullURL,json=body,headers=_headers)
            #    conn = http.client.HTTPSConnection(self.hostname)
            #    if (body == None):
            #        conn.request(action, url,headers= _headers)
            #    else:
            #        conn.request(action, url,body,_headers)
            #        print("Finished request with body")
            #    response = conn.getresponse()
            #    #data = str(response.read())
            #    data = response.read().decode('utf8')
            #    conn.close()
            except Exception as e:
                  print("[Errno {0}] {1}".format(e.errno, e.strerror)) 
                  result['code'] = 404
                  result['response'] = data
                  return result
            if response.status_code in (200, 202):
                  result['code'] = response.status_code
                  result['response'] = response.text

                  print(response.text)