"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var path = require("path");
var rimraf = require("rimraf");
var config_1 = require("../config");
var utils_1 = require("../utils");
var binary_1 = require("./binary");
function getAndroidArch() {
    switch (config_1.Config.osArch()) {
        case 'arm':
            return 'armeabi-v7a';
        case 'arm64':
            return 'arm64-v8a';
        case 'x86':
        case 'x32':
        case 'ia32':
        case 'ppc':
            return 'x86';
        case 'x86-64':
        case 'x64':
        case 'ia64':
        case 'ppc64':
            return 'x86_64';
        default:
            return config_1.Config.osArch();
    }
}
/**
 * The android sdk binary.
 */
var AndroidSDK = (function (_super) {
    __extends(AndroidSDK, _super);
    function AndroidSDK(alternateCDN) {
        var _this = _super.call(this, alternateCDN || config_1.Config.cdnUrls().android) || this;
        _this.name = 'android-sdk';
        _this.versionCustom = AndroidSDK.versionDefault;
        _this.prefixDefault = 'android-sdk_r';
        _this.suffixDefault = '.zip';
        return _this;
    }
    AndroidSDK.prototype.id = function () {
        return AndroidSDK.id;
    };
    AndroidSDK.prototype.versionDefault = function () {
        return AndroidSDK.versionDefault;
    };
    AndroidSDK.prototype.suffix = function (ostype) {
        if (ostype === 'Darwin') {
            return '-macosx' + this.suffixDefault;
        }
        else if (ostype === 'Linux') {
            return '-linux.tgz';
        }
        else if (ostype === 'Windows_NT') {
            return '-windows' + this.suffixDefault;
        }
    };
    AndroidSDK.prototype.url = function (ostype) {
        return this.cdn + this.filename(ostype);
    };
    AndroidSDK.prototype.zipContentName = function (ostype) {
        if (ostype === 'Darwin') {
            return this.name + '-macosx';
        }
        else if (ostype === 'Linux') {
            return this.name + '-linux';
        }
        else if (ostype === 'Windows_NT') {
            return this.name + '-windows';
        }
    };
    AndroidSDK.prototype.executableSuffix = function () {
        return '';
    };
    AndroidSDK.prototype.remove = function (sdkPath) {
        try {
            var avds = require(path.resolve(sdkPath, 'available_avds.json'));
            var version_1 = path.basename(sdkPath).slice(this.prefixDefault.length);
            avds.forEach(function (avd) {
                utils_1.spawnSync(path.resolve(sdkPath, 'tools', 'android'), ['delete', 'avd', '-n', avd + '-v' + version_1 + '-wd-manager']);
            });
        }
        catch (e) {
        }
        rimraf.sync(sdkPath);
    };
    return AndroidSDK;
}(binary_1.Binary));
AndroidSDK.os = [binary_1.OS.Windows_NT, binary_1.OS.Linux, binary_1.OS.Darwin];
AndroidSDK.id = 'android';
AndroidSDK.versionDefault = config_1.Config.binaryVersions().android;
AndroidSDK.isDefault = false;
AndroidSDK.shortName = ['android'];
AndroidSDK.DEFAULT_API_LEVELS = '24';
AndroidSDK.DEFAULT_ARCHITECTURES = getAndroidArch();
AndroidSDK.DEFAULT_PLATFORMS = 'google_apis';
AndroidSDK.VERSIONS = {
    // Before 24 is not supported
    24: '7.0',
    25: '7.1'
};
exports.AndroidSDK = AndroidSDK;
//# sourceMappingURL=android_sdk.js.map