/*
* Copyright 2018 Huawei Technologies Co.,Ltd.
* 
* 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.
*
*
* Error: Parse Error: Header overflow
* Cause：The header overflows because the response header X-Subject-Token exceeds the default size of 8 KB.
* Set the environment variable: set NODE_OPTIONS=--max-http-header-size=16384 to 16k.
**/

const http = require('http');
const HwOcrClientToken = require('./hw/ocr-client-token');
const OcrClientAksk = require('./hw/orc-client-aksk');
const config = require('./hw/libs/config.js')

// // token
// let domainName = 'xxx'; // if the user isn't IAM user, domainName is the same with username
// let username = 'xxx';
// let password = 'xxx';
// let region = 'ap-southeast-1';
// let httpUri1 = '/v1.0/ocr/passport';
// let hwOcrClientToken = new HwOcrClientToken(domainName,username, password, region);
// let img_path = './data/passport-demo.jpg'
// let opt1 = {};
// //let opt1 = {'country_code': 'GENERAL'}; // option
// hwOcrIdCard(hwOcrClientToken, httpUri1, img_path, opt1);

// ak/sk
let appKey = 'xxx'; // your ak
let appSecret = 'xxx'; // your sk
let endPoint2 = 'ocr.ap-southeast-1.myhuaweicloud.com';
let httpUri2 = '/v1.0/ocr/passport';
let ocrClientAksk = new OcrClientAksk(appKey, appSecret, endPoint2);
let img_path = './data/passport-demo.jpg';
let opt2 = {};
//let opt2 = {'country_code': 'GENERAL'}; // option
hwOcrIdCard(ocrClientAksk, httpUri2, img_path, opt2);


function hwOcrIdCard (ocrClient, httpUri, filePath, opt=null) {
    ocrClient.requestOcrServiceBase64(httpUri, filePath, opt).then(result => {
        console.log('statusCode = ' + result.statusCode);
		console.log('recognize result = '+JSON.stringify(result.result));
    }).catch(error => {
        console.log(error)
    });
}
