"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const constants_1 = require("../../common/constants");
class GradleBuildArgsService {
    constructor($androidToolsInfo, $logger) {
        this.$androidToolsInfo = $androidToolsInfo;
        this.$logger = $logger;
    }
    getBuildTaskArgs(buildConfig) {
        const args = this.getBaseTaskArgs(buildConfig);
        args.unshift(this.getBuildTaskName(buildConfig));
        return args;
    }
    getCleanTaskArgs(buildConfig) {
        const args = this.getBaseTaskArgs(buildConfig);
        args.unshift("clean");
        return args;
    }
    getBaseTaskArgs(buildConfig) {
        const args = this.getBuildLoggingArgs();
        const toolsInfo = this.$androidToolsInfo.getToolsInfo();
        args.push(`-PcompileSdk=android-${toolsInfo.compileSdkVersion}`, `-PtargetSdk=${toolsInfo.targetSdkVersion}`, `-PbuildToolsVersion=${toolsInfo.buildToolsVersion}`, `-PgenerateTypings=${toolsInfo.generateTypings}`);
        if (buildConfig.release) {
            args.push("-Prelease", `-PksPath=${path.resolve(buildConfig.keyStorePath)}`, `-Palias=${buildConfig.keyStoreAlias}`, `-Ppassword=${buildConfig.keyStoreAliasPassword}`, `-PksPassword=${buildConfig.keyStorePassword}`);
        }
        return args;
    }
    getBuildLoggingArgs() {
        const args = [];
        const logLevel = this.$logger.getLevel();
        if (logLevel === "TRACE") {
            args.push("--stacktrace", "--debug");
        }
        else if (logLevel === "INFO") {
            args.push("--quiet");
        }
        return args;
    }
    getBuildTaskName(buildConfig) {
        const baseTaskName = buildConfig.androidBundle ? "bundle" : "assemble";
        const buildTaskName = buildConfig.release ? `${baseTaskName}${constants_1.Configurations.Release}` : `${baseTaskName}${constants_1.Configurations.Debug}`;
        return buildTaskName;
    }
}
exports.GradleBuildArgsService = GradleBuildArgsService;
$injector.register("gradleBuildArgsService", GradleBuildArgsService);
