/*
 * SPDX-FileCopyrightText: 2022-2023 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

import groovy.util.Node
import groovy.util.NodeList
import groovy.xml.XmlParser

plugins {
    id("com.android.application")
    id("kotlin-android")
}

android {
    compileSdk = 33

    defaultConfig {
        applicationId = "org.lineageos.aperture"
        minSdk = 26
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"
    }

    buildTypes {
        getByName("release") {
            // Enables code shrinking, obfuscation, and optimization.
            isMinifyEnabled = true

            // Enables resource shrinking.
            isShrinkResources = true

            // Includes the default ProGuard rules files.
            setProguardFiles(
                listOf(
                    getDefaultProguardFile("proguard-android-optimize.txt"),
                    "proguard-rules.pro"
                )
            )
        }
        getByName("debug") {
            // Append .dev to package name so we won't conflict with AOSP build.
            applicationIdSuffix = ".dev"
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

    implementation("androidx.core:core-ktx:1.10.1")
    implementation("androidx.activity:activity-ktx:1.7.2")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("androidx.exifinterface:exifinterface:1.3.6")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
    implementation("androidx.preference:preference:1.2.0")
    implementation("com.google.android.material:material:1.9.0")

    // CameraX core library using the camera2 implementation
    val cameraxVersion = "1.3.0-rc01"
    // The following line is optional, as the core library is included indirectly by camera-camera2
    implementation("androidx.camera:camera-core:${cameraxVersion}")
    implementation("androidx.camera:camera-camera2:${cameraxVersion}")
    // If you want to additionally use the CameraX Lifecycle library
    implementation("androidx.camera:camera-lifecycle:${cameraxVersion}")
    // If you want to additionally use the CameraX VideoCapture library
    implementation("androidx.camera:camera-video:${cameraxVersion}")
    // If you want to additionally use the CameraX View class
    implementation("androidx.camera:camera-view:${cameraxVersion}")
    // If you want to additionally use the CameraX Extensions library
    implementation("androidx.camera:camera-extensions:${cameraxVersion}")

    // Media3
    val media3Version = "1.1.1"
    // For media playback using ExoPlayer
    implementation("androidx.media3:media3-exoplayer:$media3Version")
    // For building media playback UIs
    implementation("androidx.media3:media3-ui:$media3Version")

    // ZXing
    implementation("com.google.zxing:core:3.5.0")

    // Coil
    implementation("io.coil-kt:coil:2.2.2")
    implementation("io.coil-kt:coil-video:2.2.2")
}

tasks.register("generateBp") {
    val project = project(":app")
    val configuration = project.configurations["debugRuntimeClasspath"]

    val libsBase = File("${project.projectDir.absolutePath}/libs")
    libsBase.deleteRecursively()

    val moduleString = { it: ModuleVersionIdentifier -> "${it.group}:${it.name}:${it.version}" }
    val modulePath =
        { it: ModuleVersionIdentifier -> "${it.group.replace(".", "/")}/${it.name}/${it.version}" }

    val spaces = { it: Int ->
        var ret = ""
        for (i in it downTo 1) {
            ret += ' '
        }
        ret
    }

    val moduleName = { it: Any ->
        when (it) {
            is ModuleVersionIdentifier -> {
                "${rootProject.name}_${it.group}_${it.name}"
            }
            is String -> {
                if (it.contains(":")) {
                    val (group, artifactId) = it.split(":")
                    "${rootProject.name}_${group}_${artifactId}"
                } else {
                    "${rootProject.name}_${it}"
                }
            }
            else -> {
                throw Exception("Invalid `it` type")
            }
        }
    }

    val moduleNameAosp = { it: String ->
        when (it) {
            "androidx.constraintlayout:constraintlayout" -> "androidx-constraintlayout_constraintlayout"
            "com.google.auto.value:auto-value-annotations" -> "auto_value_annotations"
            "com.google.guava:guava" -> "guava"
            "com.google.guava:listenablefuture" -> "guava"
            "org.jetbrains.kotlin:kotlin-stdlib" -> "kotlin-stdlib"
            "org.jetbrains.kotlin:kotlin-stdlib-jdk8" -> "kotlin-stdlib-jdk8"
            "org.jetbrains.kotlinx:kotlinx-coroutines-android" -> "kotlinx-coroutines-android"
            else -> it.replace(":", "_")
        }
    }

    val isAvailableInAosp = { group: String, artifactId: String ->
        when {
            group.startsWith("androidx") -> {
                // We provide our own androidx.{camera,media3} & lifecycle-common
                !group.startsWith("androidx.camera") &&
                        !group.startsWith("androidx.media3") &&
                        artifactId != "lifecycle-common"
            }
            group.startsWith("org.jetbrains") -> true
            group == "com.google.auto.value" -> true
            group == "com.google.guava" -> true
            group == "junit" -> true
            else -> false
        }
    }

    // Update app/Android.bp
    File("${project.projectDir.absolutePath}/Android.bp").let { file ->
        // Read dependencies
        val dependencies = "${spaces(8)}// DO NOT EDIT THIS SECTION MANUALLY\n".plus(
            configuration.allDependencies.filter {
                // kotlin-bom does not need to be added to dependencies
                it.group != "org.jetbrains.kotlin" && it.name != "kotlin-bom"
            }.joinToString("\n") {
                if (isAvailableInAosp(it.group!!, it.name)) {
                    "${spaces(8)}\"${moduleNameAosp("${it.group}:${it.name}")}\","
                } else {
                    "${spaces(8)}\"${moduleName("${it.group}:${it.name}")}\","
                }
            }
        )

        // Replace existing dependencies with newly generated ones
        file.writeText(
            file.readText().replace(
                "static_libs: \\[.*?\\]".toRegex(RegexOption.DOT_MATCHES_ALL),
                "static_libs: [%s]".format("\n$dependencies\n${spaces(4)}")
            )
        )
    }

    // Update app/libs
    configuration.resolvedConfiguration.resolvedArtifacts.sortedBy {
        moduleString(it.moduleVersion.id)
    }.distinctBy {
        moduleString(it.moduleVersion.id)
    }.forEach {
        val id = it.moduleVersion.id

        // Skip modules that are available in AOSP
        if (isAvailableInAosp(id.group, it.name)) {
            return@forEach
        }

        // Get file path
        val dirPath = "${libsBase}/${modulePath(id)}"
        val filePath = "${dirPath}/${it.file.name}"

        // Copy artifact to app/libs
        it.file.copyTo(File(filePath))

        // Parse dependencies
        val dependencies =
            it.file.parentFile.parentFile.walk().filter { file -> file.extension == "pom" }
                .map { file ->
                    val ret = mutableListOf<String>()

                    val pom = XmlParser().parse(file)
                    val dependencies = (pom["dependencies"] as NodeList).firstOrNull() as Node?

                    dependencies?.children()?.forEach { node ->
                        val dependency = node as Node
                        ret.add(
                            "${
                                (dependency.get("groupId") as NodeList).text()
                            }:${
                                (dependency.get("artifactId") as NodeList).text()
                            }"
                        )
                    }

                    ret
                }.flatten()

        var targetSdkVersion = android.defaultConfig.targetSdk
        var minSdkVersion = 14

        // Extract AndroidManifest.xml for AARs
        if (it.file.extension == "aar") {
            copy {
                from(zipTree(filePath).matching { include("/AndroidManifest.xml") }.singleFile)
                into(dirPath)
            }

            val androidManifest = XmlParser().parse(File("${dirPath}/AndroidManifest.xml"))

            val usesSdk = (androidManifest["uses-sdk"] as NodeList).first() as Node
            targetSdkVersion = (usesSdk.get("@targetSdkVersion") as Int?) ?: targetSdkVersion
            minSdkVersion = (usesSdk.get("@minSdkVersion") as Int?) ?: minSdkVersion
        }

        // Write Android.bp
        File("$libsBase/Android.bp").let { file ->
            // Add autogenerated header if file is empty
            if (file.length() == 0L) {
                file.writeText("// DO NOT EDIT THIS FILE MANUALLY")
            }

            val formatDeps = { addNoDeps: Boolean ->
                val deps = dependencies.filter { dep ->
                    when {
                        configuration.resolvedConfiguration.resolvedArtifacts.firstOrNull { artifact ->
                            dep == "${artifact.moduleVersion.id.group}:${artifact.moduleVersion.id.name}"
                        } == null -> {
                            val moduleName = if (addNoDeps) {
                                moduleName(id)
                            } else {
                                "${moduleName(id)}-nodeps"
                            }
                            println("$moduleName: Skipping $dep because it's not in resolvedArtifacts")
                            false
                        }
                        dep == "org.jetbrains.kotlin:kotlin-stdlib-common" -> false
                        else -> true
                    }
                }.distinct().toMutableList()

                if (addNoDeps) {
                    // Add -nodeps dependency for android_library/java_library_static
                    deps.add(0, "${id.group}_${id.name}-nodeps")
                }

                var ret = ""

                if (deps.isNotEmpty()) {
                    deps.forEach { dep ->
                        ret += if (dep.contains(":")) {
                            val (group, artifactId) = dep.split(":")
                            if (isAvailableInAosp(group, artifactId)) {
                                "\n${spaces(8)}\"${moduleNameAosp(dep)}\","
                            } else {
                                "\n${spaces(8)}\"${moduleName(dep)}\","
                            }
                        } else {
                            "\n${spaces(8)}\"${moduleName(dep)}\","
                        }
                    }
                    ret += "\n${spaces(4)}"
                }

                ret
            }

            when (it.extension) {
                "aar" -> {
                    file.appendText(
                        """

                            android_library_import {
                                name: "${moduleName(id)}-nodeps",
                                aars: ["${modulePath(id)}/${it.file.name}"],
                                sdk_version: "$targetSdkVersion",
                                min_sdk_version: "$minSdkVersion",
                                apex_available: [
                                    "//apex_available:platform",
                                    "//apex_available:anyapex",
                                ],
                                static_libs: [%s],
                            }

                            android_library {
                                name: "${moduleName(id)}",
                                sdk_version: "$targetSdkVersion",
                                min_sdk_version: "$minSdkVersion",
                                apex_available: [
                                    "//apex_available:platform",
                                    "//apex_available:anyapex",
                                ],
                                manifest: "${modulePath(id)}/AndroidManifest.xml",
                                static_libs: [%s],
                                java_version: "1.7",
                            }

                        """.trimIndent().format(formatDeps(false), formatDeps(true))
                    )
                }
                "jar" -> {
                    file.appendText(
                        """

                            java_import {
                                name: "${moduleName(id)}-nodeps",
                                jars: ["${modulePath(id)}/${it.file.name}"],
                                sdk_version: "$targetSdkVersion",
                                min_sdk_version: "$minSdkVersion",
                                apex_available: [
                                    "//apex_available:platform",
                                    "//apex_available:anyapex",
                                ],
                            }

                            java_library_static {
                                name: "${moduleName(id)}",
                                sdk_version: "$targetSdkVersion",
                                min_sdk_version: "$minSdkVersion",
                                apex_available: [
                                    "//apex_available:platform",
                                    "//apex_available:anyapex",
                                ],
                                static_libs: [%s],
                                java_version: "1.7",
                            }

                        """.trimIndent().format(formatDeps(true))
                    )
                }
                else -> throw Exception("Unknown file extension: ${it.extension}")
            }
        }
    }
}
