"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
exports.__esModule = true;
exports.deviceInternalCodeName = exports.OSV2DeviceTargetNames = exports.OSV2Devices = exports.deviceTargets = exports.DeviceScreenType = exports.DeviceSource = exports.DevicePlatformName = exports.DeviceTarget = void 0;
var lodash_1 = require("lodash");
var device_server_1 = __importDefault(require("./device-server"));
var tools_1 = require("../tools/tools");
var DeviceTarget;
(function (DeviceTarget) {
    DeviceTarget["MADRID"] = "madrid";
    DeviceTarget["VERONA"] = "verona";
    DeviceTarget["ZURICH"] = "zurich";
    DeviceTarget["TEIDE"] = "teide";
    DeviceTarget["PROVENCE"] = "provence";
    DeviceTarget["BARI"] = "bari";
    DeviceTarget["BERLIN"] = "berlin";
    DeviceTarget["LILLE"] = "lille";
    DeviceTarget["VIENNA"] = "vienna";
    DeviceTarget["ANDES"] = "andes";
    DeviceTarget["MONACO"] = "monaco";
    DeviceTarget["SWIFT"] = "swift";
    DeviceTarget["SWORDFISH"] = "swordfishw";
    DeviceTarget["CHEETAH"] = "cheetahw";
    DeviceTarget["HANNOVER"] = "hannover";
    DeviceTarget["ETNA"] = "etna";
    DeviceTarget["ALTAI"] = "altai";
})(DeviceTarget = exports.DeviceTarget || (exports.DeviceTarget = {}));
var DevicePlatformName;
(function (DevicePlatformName) {
    DevicePlatformName["MADRID"] = "gtr3-pro";
    DevicePlatformName["MADRIDW"] = "gtr3-pro-w";
    DevicePlatformName["Madrid2"] = "gtr3-pro-meilin";
    DevicePlatformName["VERONA"] = "gtr3";
    DevicePlatformName["VERONAW"] = "gtr3-w";
    DevicePlatformName["ZURICH"] = "gts3";
    DevicePlatformName["ZURICHW"] = "gts3-w";
    DevicePlatformName["TEIDE"] = "t-rex2";
    DevicePlatformName["TEIDEW"] = "t-rex2-w";
    DevicePlatformName["PROVENCE"] = "gts4-mini";
    DevicePlatformName["PROVENCEW"] = "gts4-mini-w";
    DevicePlatformName["BARI_NFC"] = "amazfit-band7-nfc";
    DevicePlatformName["BARI"] = "amazfit-band7";
    DevicePlatformName["BARI_W"] = "amazfit-band7-w";
    DevicePlatformName["BERLIN"] = "gtr4";
    DevicePlatformName["BERLIN_W"] = "gtr4-w";
    DevicePlatformName["LILLE"] = "gts4";
    DevicePlatformName["LILLE_W"] = "gts4-w";
    DevicePlatformName["VIENNA"] = "falcon";
    DevicePlatformName["VIENNA_W"] = "falcon-w";
    DevicePlatformName["ANDES"] = "t-rex-ultra";
    DevicePlatformName["ANDES_W"] = "t-rex-ultra-w";
    DevicePlatformName["MONACO"] = "monaco";
    DevicePlatformName["MONACO_WN"] = "monaco-wn";
    DevicePlatformName["MONACO_W"] = "monaco-w";
    DevicePlatformName["SWIFT"] = "swift";
    DevicePlatformName["SWIFT_W"] = "swift-w";
    DevicePlatformName["SWORDFISH_W"] = "swordfish-w";
    DevicePlatformName["CHEETAH_W"] = "cheetah-w";
    DevicePlatformName["HANNOVER"] = "hannover";
    DevicePlatformName["ETNA"] = "etna";
    DevicePlatformName["ETNA_W"] = "etna-w";
    DevicePlatformName["ALTAI"] = "altai";
})(DevicePlatformName = exports.DevicePlatformName || (exports.DevicePlatformName = {}));
var DeviceSource;
(function (DeviceSource) {
    DeviceSource[DeviceSource["MADRID"] = 229] = "MADRID";
    DeviceSource[DeviceSource["MADRIDW"] = 230] = "MADRIDW";
    DeviceSource[DeviceSource["Madrid2"] = 6095106] = "Madrid2";
    DeviceSource[DeviceSource["VERONA"] = 226] = "VERONA";
    DeviceSource[DeviceSource["VERONAW"] = 227] = "VERONAW";
    DeviceSource[DeviceSource["ZURICH"] = 224] = "ZURICH";
    DeviceSource[DeviceSource["ZURICHW"] = 225] = "ZURICHW";
    DeviceSource[DeviceSource["TEIDE"] = 418] = "TEIDE";
    DeviceSource[DeviceSource["TEIDEW"] = 419] = "TEIDEW";
    DeviceSource[DeviceSource["PROVENCE"] = 246] = "PROVENCE";
    DeviceSource[DeviceSource["PROVENCEW"] = 247] = "PROVENCEW";
    DeviceSource[DeviceSource["BARI_NFC"] = 252] = "BARI_NFC";
    DeviceSource[DeviceSource["BARI"] = 253] = "BARI";
    DeviceSource[DeviceSource["BARI_W"] = 254] = "BARI_W";
    DeviceSource[DeviceSource["BERLIN"] = 7930112] = "BERLIN";
    DeviceSource[DeviceSource["BERLIN_W"] = 7930113] = "BERLIN_W";
    DeviceSource[DeviceSource["LILLE"] = 7995648] = "LILLE";
    DeviceSource[DeviceSource["LILLE_W"] = 7995649] = "LILLE_W";
    DeviceSource[DeviceSource["VIENNA"] = 414] = "VIENNA";
    DeviceSource[DeviceSource["VIENNA_W"] = 415] = "VIENNA_W";
    DeviceSource[DeviceSource["ANDES"] = 6553856] = "ANDES";
    DeviceSource[DeviceSource["ANDES_W"] = 6553857] = "ANDES_W";
    DeviceSource[DeviceSource["MONACO"] = 8519936] = "MONACO";
    DeviceSource[DeviceSource["MONACO_WN"] = 8519937] = "MONACO_WN";
    DeviceSource[DeviceSource["MONACO_W"] = 8519939] = "MONACO_W";
    DeviceSource[DeviceSource["SWIFT"] = 8192256] = "SWIFT";
    DeviceSource[DeviceSource["SWIFT_W"] = 8192257] = "SWIFT_W";
    DeviceSource[DeviceSource["SWORDFISH_W"] = 8257793] = "SWORDFISH_W";
    DeviceSource[DeviceSource["CHEETAH_W"] = 8126721] = "CHEETAH_W";
    DeviceSource[DeviceSource["HANNOVER"] = 8323329] = "HANNOVER";
    DeviceSource[DeviceSource["ETNA"] = 8388864] = "ETNA";
    DeviceSource[DeviceSource["ETNA_W"] = 8388865] = "ETNA_W";
    DeviceSource[DeviceSource["ALTAI"] = 8454401] = "ALTAI";
})(DeviceSource = exports.DeviceSource || (exports.DeviceSource = {}));
var DeviceScreenType;
(function (DeviceScreenType) {
    DeviceScreenType["R"] = "r";
    DeviceScreenType["S"] = "s";
    DeviceScreenType["B"] = "b";
})(DeviceScreenType = exports.DeviceScreenType || (exports.DeviceScreenType = {}));
exports.deviceTargets = __assign((_a = {}, _a[DeviceTarget.MADRID] = {
    deviceName: 'GTR3 Pro',
    platforms: [
        {
            name: DevicePlatformName.MADRID,
            deviceSource: DeviceSource.MADRID
        },
        {
            name: DevicePlatformName.MADRIDW,
            deviceSource: DeviceSource.MADRIDW
        },
        {
            name: DevicePlatformName.Madrid2,
            deviceSource: DeviceSource.Madrid2
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 480,
        height: 480
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.VERONA] = {
    deviceName: 'GTR3',
    platforms: [
        {
            name: DevicePlatformName.VERONA,
            deviceSource: DeviceSource.VERONA
        },
        {
            name: DevicePlatformName.VERONAW,
            deviceSource: DeviceSource.VERONAW
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 454,
        height: 454
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.ZURICH] = {
    deviceName: 'GTS3',
    platforms: [
        {
            name: DevicePlatformName.ZURICH,
            deviceSource: DeviceSource.ZURICH
        },
        {
            name: DevicePlatformName.ZURICHW,
            deviceSource: DeviceSource.ZURICHW
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 390,
        height: 450
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.TEIDE] = {
    deviceName: 'T-Rex2',
    platforms: [
        {
            name: DevicePlatformName.TEIDE,
            deviceSource: DeviceSource.TEIDE
        },
        {
            name: DevicePlatformName.TEIDEW,
            deviceSource: DeviceSource.TEIDEW
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 454,
        height: 454
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.PROVENCE] = {
    deviceName: 'GTS4 mini',
    platforms: [
        {
            name: DevicePlatformName.PROVENCE,
            deviceSource: DeviceSource.PROVENCE
        },
        {
            name: DevicePlatformName.PROVENCEW,
            deviceSource: DeviceSource.PROVENCEW
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 336,
        height: 384
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.BARI] = {
    deviceName: 'Amazfit Band 7',
    platforms: [
        {
            name: DevicePlatformName.BARI_NFC,
            deviceSource: DeviceSource.BARI_NFC
        },
        {
            name: DevicePlatformName.BARI,
            deviceSource: DeviceSource.BARI
        },
        {
            name: DevicePlatformName.BARI_W,
            deviceSource: DeviceSource.BARI_W
        },
    ],
    screen: {
        type: DeviceScreenType.B,
        width: 194,
        height: 368
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.BERLIN] = {
    deviceName: 'GTR 4',
    platforms: [
        {
            name: DevicePlatformName.BERLIN,
            deviceSource: DeviceSource.BERLIN
        },
        {
            name: DevicePlatformName.BERLIN_W,
            deviceSource: DeviceSource.BERLIN_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 466,
        height: 466
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.LILLE] = {
    deviceName: 'GTS 4',
    platforms: [
        {
            name: DevicePlatformName.LILLE,
            deviceSource: DeviceSource.LILLE
        },
        {
            name: DevicePlatformName.LILLE_W,
            deviceSource: DeviceSource.LILLE_W
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 390,
        height: 450
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.VIENNA] = {
    deviceName: 'Falcon',
    platforms: [
        {
            name: DevicePlatformName.VIENNA,
            deviceSource: DeviceSource.VIENNA
        },
        {
            name: DevicePlatformName.VIENNA_W,
            deviceSource: DeviceSource.VIENNA_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 416,
        height: 416
    },
    apiLevelLimit: {
        min: '1.0.0',
        max: '1.99.99'
    }
}, _a[DeviceTarget.ANDES] = {
    deviceName: 'T-Rex Ultra',
    platforms: [
        {
            name: DevicePlatformName.ANDES,
            deviceSource: DeviceSource.ANDES
        },
        {
            name: DevicePlatformName.ANDES_W,
            deviceSource: DeviceSource.ANDES_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 454,
        height: 454
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.MONACO] = {
    deviceName: 'Amazfit Balance',
    platforms: [
        {
            name: DevicePlatformName.MONACO,
            deviceSource: DeviceSource.MONACO
        },
        {
            name: DevicePlatformName.MONACO_WN,
            deviceSource: DeviceSource.MONACO_WN
        },
        {
            name: DevicePlatformName.MONACO_W,
            deviceSource: DeviceSource.MONACO_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 480,
        height: 480
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.SWIFT] = {
    deviceName: 'Runner (Round)',
    platforms: [
        {
            name: DevicePlatformName.SWIFT,
            deviceSource: DeviceSource.SWIFT
        },
        {
            name: DevicePlatformName.SWIFT_W,
            deviceSource: DeviceSource.SWIFT_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 454,
        height: 454
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.SWORDFISH] = {
    deviceName: 'Runner (Square)',
    platforms: [
        {
            name: DevicePlatformName.SWORDFISH_W,
            deviceSource: DeviceSource.SWORDFISH_W
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 390,
        height: 450
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.CHEETAH] = {
    deviceName: 'Runner Pro',
    platforms: [
        {
            name: DevicePlatformName.CHEETAH_W,
            deviceSource: DeviceSource.CHEETAH_W
        },
    ],
    screen: {
        type: DeviceScreenType.R,
        width: 480,
        height: 480
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.HANNOVER] = {
    deviceName: 'GTS 5 Active',
    platforms: [
        {
            name: DevicePlatformName.HANNOVER,
            deviceSource: DeviceSource.HANNOVER
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 390,
        height: 450
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.ETNA] = {
    deviceName: 'GTR Shock',
    platforms: [
        {
            name: DevicePlatformName.ETNA,
            deviceSource: DeviceSource.ETNA
        },
        {
            name: DevicePlatformName.ETNA_W,
            deviceSource: DeviceSource.ETNA_W
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 360,
        height: 360
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a[DeviceTarget.ALTAI] = {
    deviceName: 'Bip 5s',
    platforms: [
        {
            name: DevicePlatformName.ALTAI,
            deviceSource: DeviceSource.ALTAI
        },
    ],
    screen: {
        type: DeviceScreenType.S,
        width: 320,
        height: 380
    },
    apiLevelLimit: {
        min: '1.0.0'
    }
}, _a), device_server_1["default"]);
exports.OSV2Devices = Object.values(exports.deviceTargets).reduce(function (targetDevices, target) {
    var _a = target.platforms, platforms = _a === void 0 ? [] : _a, _b = target.apiLevelLimit, apiLevelLimit = _b === void 0 ? {} : _b;
    var min = apiLevelLimit.min, max = apiLevelLimit.max;
    if (!(0, lodash_1.isEmpty)(platforms) &&
        (0, tools_1.compareVersion)(min || '1.0.0', '2.0.0') >= 0 &&
        max && (0, tools_1.compareVersion)(max, '2.0.0') <= 0) {
        targetDevices.push.apply(targetDevices, platforms.reduce(function (list, o) { return (0, lodash_1.compact)(list.concat([o.deviceSource])); }, []));
    }
    return targetDevices;
}, []);
exports.OSV2DeviceTargetNames = Object.keys(exports.deviceTargets).reduce(function (targetNames, target) {
    var flag = true;
    var _a = exports.deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
    if (platforms && platforms.length) {
        platforms.forEach(function (_a) {
            var deviceSource = _a.deviceSource;
            if (!exports.OSV2Devices.includes(deviceSource)) {
                flag = false;
            }
        });
    }
    else {
        flag = false;
    }
    flag && targetNames.push(target);
    return targetNames;
}, []);
exports.deviceInternalCodeName = Object.keys(exports.deviceTargets).reduce(function (deviceSources, target) {
    var _a = exports.deviceTargets[target].platforms, platforms = _a === void 0 ? [] : _a;
    platforms.forEach(function (_a) {
        var deviceSource = _a.deviceSource;
        deviceSource && (deviceSources[deviceSource] = target);
    });
    return deviceSources;
}, {});
