import os.path

from scripts.task import Task
from utils import SystemUtils, CommandUtils
from utils.logger_utils import app_logger


class ProjectBuild(Task):
    """
    assembleLawnWithQuickstepPlay
    bundleLawnWithQuickstepPlayRelease
    """

    def gradlew(self):
        gradlew = os.path.abspath(os.path.join(self.context.temp_project_path, "gradlew"))
        if SystemUtils.is_windows():
            gradlew += ".bat"
        return gradlew

    def build_apk(self):
        cmd = f"{self.gradlew()} -p {self.context.temp_project_path} assembleLawnWithQuickstepPlay"
        app_logger().debug(f"build apk cmd = {cmd}")
        return_code, stdout, stderr = CommandUtils.execute(cmd)
        app_logger().debug(f"build apk return_code = {return_code} stdout = {stdout} stderr = {stderr}")

    def build_aab(self):
        cmd = f"{self.gradlew()} -p {self.context.temp_project_path} bundleLawnWithQuickstepPlayRelease"
        app_logger().debug(f"build aab cmd = {cmd}")
        return_code, stdout, stderr = CommandUtils.execute(cmd)
        app_logger().debug(f"build aab return_code = {return_code} stdout = {stdout} stderr = {stderr}")

    def execute(self):
        self.build_apk()
        self.build_aab()

        pass
