1'use strict';
2
3const EventEmitter = require('events');
4
5class UTILS_APPOTA extends EventEmitter {
6    constructor(options){
7        super();
8
9        if (!options) {
10            throw new Error('options invalid');
11        }
12
13        this._init(options);
14    }
15
16    _init(options) {
17        __native.APPOTA.otaInit(options, function(res) {
18            this.emit('new', res);
19        }.bind(this));
20    }
21
22    download(options, cb) {
23        __native.APPOTA.otaDownload(options, cb);
24    }
25
26    verify(options, cb) {
27        __native.APPOTA.otaVerify(options, cb);
28    }
29
30    report(options) {
31        var res = __native.APPOTA.otaReport(options);
32        if (res < 0) {
33            this.emit('error');
34        }
35    }
36
37    upgrade(options, cb) {
38        __native.APPOTA.otaUpgrade(options, cb);
39    }
40}
41
42function open(options) {
43    return new UTILS_APPOTA(options);
44}
45
46module.exports = {
47    open
48}