/*
* 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.
*/


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 username = 'xxx';
//let password = 'xxx';
//let region = 'cn-north-1';
//let endPoint = 'ocr.cn-north-1.myhuaweicloud.com';
//let domainName = 'xxx'; // if the user isn't IAM user, domainName is the same with username
//let hwOcrClientToken = new HwOcrClientToken(domainName,username, password, region, endPoint);
//let opt = {'side': 'front'}; // option,
//hwOcrIdCard(hwOcrClientToken, './data/id-card-demo.png', opt);

// ak/sk
  let appKey = 'xxx'; // your ak
  let appSecret = 'xxx'; // your sk
  let endPoint = 'ocr.cn-north-1.myhuaweicloud.com';
  let ocrClientAksk = new OcrClientAksk(appKey, appSecret, endPoint);
  let opt = {'side': 'front'}; // option,
  hwOcrIdCard(ocrClientAksk, './data/id-card-demo.png',opt);


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