"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 semver = require("semver");
var config_1 = require("../config");
var binary_1 = require("./binary");
/**
 * The gecko driver binary.
 */
var GeckoDriver = (function (_super) {
    __extends(GeckoDriver, _super);
    function GeckoDriver(alternateCDN) {
        var _this = _super.call(this, alternateCDN || config_1.Config.cdnUrls().gecko) || this;
        _this.name = 'geckodriver';
        _this.versionCustom = GeckoDriver.versionDefault;
        _this.prefixDefault = 'geckodriver-';
        return _this;
    }
    GeckoDriver.prototype.id = function () {
        return GeckoDriver.id;
    };
    GeckoDriver.prototype.versionDefault = function () {
        return GeckoDriver.versionDefault;
    };
    GeckoDriver.prototype.suffix = function (ostype, arch) {
        if (!GeckoDriver.suffixes[ostype][arch]) {
            throw new Error('GeckoDriver doesn\'t support ${ostype} ${arch}!');
        }
        var version = this.version();
        // No 32-bit builds before 0.10.0
        if (semver.lte(version, '0.10.0')) {
            if (arch === 'x64') {
                throw new Error('GeckoDriver doesn\'t support ${ostype} ${arch}!');
            }
        }
        // Special case old versions on Mac for the name change.
        if (semver.lte(version, '0.9.0')) {
            if (ostype === 'Darwin') {
                return '-mac.tar.gz';
            }
        }
        return GeckoDriver.suffixes[ostype][arch];
    };
    GeckoDriver.supports = function (ostype, arch) {
        return !!GeckoDriver.suffixes[ostype][arch];
    };
    GeckoDriver.prototype.url = function (ostype, arch) {
        var urlBase = this.cdn + this.version() + '/';
        var filename = this.prefix() + this.version() + this.suffix(ostype, arch);
        return urlBase + filename;
    };
    return GeckoDriver;
}(binary_1.Binary));
GeckoDriver.os = [binary_1.OS.Windows_NT, binary_1.OS.Linux, binary_1.OS.Darwin];
GeckoDriver.id = 'gecko';
GeckoDriver.versionDefault = config_1.Config.binaryVersions().gecko;
GeckoDriver.isDefault = true;
GeckoDriver.shortName = ['gecko'];
GeckoDriver.suffixes = {
    'Darwin': { 'x64': '-macos.tar.gz' },
    'Linux': { 'x64': '-linux64.tar.gz', 'ia32': '-linux32.tar.gz' },
    'Windows_NT': {
        'x64': '-win64.zip',
        'ia32': '-win32.zip',
    }
};
exports.GeckoDriver = GeckoDriver;
//# sourceMappingURL=gecko_driver.js.map