#coding=utf-8
import HttpUtils

# 添加用户 https://{host}/user/addPersonalUser
def addPerson(inputData):
    # 从输入数据中获取调用接口
    account = inputData["account"]
    name = inputData["name"]
    mobile = inputData["mobile"]
    idCard = inputData["idCard"]
    idCardType = inputData["idCardType"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = {
        "account": account, 
        "idCard": idCard, 
        "idCardType": idCardType,
        "identifyMobile": mobile, 
        "identifyType": 2,
        "mobile": mobile, 
        "name": name
    }
    #请求地址
    # url = "https://prev.asign.cn/user/addPersonalUser"
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result

# 上传待签署文件 https://{host}/contract/createContract
def createContract(inputData):
    # 从输入数据中获取调用接口
    contractNo = inputData["contractNo"]
    contractName = inputData["contractName"]
    validityTime = inputData["validityTime"]
    signOrder = inputData["signOrder"]
    templates = inputData["templates"]
    notifyUrl = inputData["notifyUrl"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = {
        "contractNo": contractNo, 
        "contractName": contractName, 
        "validityTime": validityTime,
        "signOrder": signOrder,
        "templates": templates, 
        "notifyUrl": notifyUrl
    }
    #请求地址
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result

# 添加签署方 https://{host}/contract/addSigner
def addSigner(inputData):
    # 从输入数据中获取调用接口
    contractNo = inputData["contractNo"]
    account = inputData["account"]
    signType = inputData["signType"]
    signStrategyList = inputData["signStrategyList"]
    validateType = inputData["validateType"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = [{
        "contractNo": contractNo, 
        "account": account, 
        "signType": signType,
        "validateType": validateType,
        "signStrategyList": signStrategyList
    }]
    #请求地址
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result

# 下载合同 https://{host}/contract/downloadContract
def downloadContract(inputData):
    # 从输入数据中获取调用接口
    contractNo = inputData["contractNo"]
    # downloadFileType = inputData["downloadFileType"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = {
        "contractNo": contractNo
        # "downloadFileType": downloadFileType
    }
    #请求地址
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result

# 查询合同状态 https://{host}/contract/status
def contractStatus(inputData):
    # 从输入数据中获取调用接口
    contractNo = inputData["contractNo"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = {
        "contractNo": contractNo
    }
    #请求地址
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result

# 个人意愿核身认证 https://{host}/auth/person/willFace
def willFace(inputData):
    # 从输入数据中获取调用接口
    realName = inputData["realName"]
    idCardNo = inputData["idCardNo"]
    question = inputData["question"]
    answer = inputData["answer"]
    redirectUrl = inputData["redirectUrl"]
    
    appId = inputData["appId"]
    appKey = inputData["appKey"]
    apiUrl = inputData["apiUrl"]

    # 组装参数
    reqBodyData = {
        "realName": realName,
        "idCardNo": idCardNo,
        "question": question,
        "answer": answer,
        "redirectUrl": redirectUrl,
    }
    #请求地址
    Result = HttpUtils.HttpUtils.doPOST(apiUrl, reqBodyData, appId, appKey)

    return Result