"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GradleBuildArgsService = void 0;
const path = require("path");
const constants_1 = require("../../common/constants");
const yok_1 = require("../../common/yok");
class GradleBuildArgsService {
    constructor($hooksService, $analyticsService, $staticConfig, $projectData, $logger) {
        this.$hooksService = $hooksService;
        this.$analyticsService = $analyticsService;
        this.$staticConfig = $staticConfig;
        this.$projectData = $projectData;
        this.$logger = $logger;
    }
    async getBuildTaskArgs(buildData) {
        const args = this.getBaseTaskArgs(buildData);
        args.unshift(this.getBuildTaskName(buildData));
        if (await this.$analyticsService.isEnabled(this.$staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME)) {
            args.push("-PgatherAnalyticsData=true");
        }
        await this.$hooksService.executeBeforeHooks("build-task-args", {
            hookArgs: { args },
        });
        return args;
    }
    getCleanTaskArgs(buildData) {
        const args = this.getBaseTaskArgs(buildData);
        args.unshift("clean");
        return args;
    }
    getBaseTaskArgs(buildData) {
        const args = this.getBuildLoggingArgs();
        this.$projectData.initializeProjectData(buildData.projectDir);
        args.push(`-PappPath=${this.$projectData.getAppDirectoryPath()}`, `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`);
        if (buildData.gradleArgs) {
            args.push(buildData.gradleArgs);
        }
        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;
yok_1.injector.register("gradleBuildArgsService", GradleBuildArgsService);
