"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(buildData) {
        const args = this.getBaseTaskArgs(buildData);
        args.unshift(this.getBuildTaskName(buildData));
        return args;
    }
    getCleanTaskArgs(buildData) {
        const args = this.getBaseTaskArgs(buildData);
        args.unshift("clean");
        return args;
    }
    getBaseTaskArgs(buildData) {
        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 (buildData.release) {
            args.push("-Prelease", `-PksPath=${path.resolve(buildData.keyStorePath)}`, `-Palias=${buildData.keyStoreAlias}`, `-Ppassword=${buildData.keyStoreAliasPassword}`, `-PksPassword=${buildData.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(buildData) {
        const baseTaskName = buildData.androidBundle ? "bundle" : "assemble";
        const buildTaskName = buildData.release ? `${baseTaskName}${constants_1.Configurations.Release}` : `${baseTaskName}${constants_1.Configurations.Debug}`;
        return buildTaskName;
    }
}
exports.GradleBuildArgsService = GradleBuildArgsService;
$injector.register("gradleBuildArgsService", GradleBuildArgsService);
