/*
 * Copyright 2023 Signal Messenger, LLC
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import java.util.Properties

plugins {
  id("signal-sample-app")
  alias(libs.plugins.compose.compiler)
}

val localPropertiesFile = File(rootProject.projectDir, "local.properties")
val localProperties: Properties? = if (localPropertiesFile.exists()) {
  Properties().apply { localPropertiesFile.inputStream().use { load(it) } }
} else {
  null
}

android {
  namespace = "org.thoughtcrime.video.app"

  compileSdk {
    version = release(libs.versions.compileSdk.get().toInt())
  }

  defaultConfig {
    applicationId = "org.thoughtcrime.video.app"
    minSdk = 26
    targetSdk = libs.versions.targetSdk.get().toInt()
    versionCode = 1
    versionName = "1.0"

    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    testInstrumentationRunnerArguments["clearPackageData"] = "true"
    vectorDrawables {
      useSupportLibrary = true
    }
  }

  testOptions {
    execution = "ANDROIDX_TEST_ORCHESTRATOR"
  }

  buildTypes {
    release {
      isMinifyEnabled = true
      isShrinkResources = true
      proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
      signingConfig = signingConfigs.getByName("debug")
    }
  }
  compileOptions {
    sourceCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
    targetCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
  }
  buildFeatures {
    compose = true
  }
  packaging {
    resources {
      excludes += setOf(
        "/META-INF/{AL2.0,LGPL2.1}",
        "**/*.dylib",
        "**/*.dll"
      )
    }
    jniLibs {
      excludes += setOf(
        "**/libsignal_jni_testing.so",
        "**/*.dylib",
        "**/*.dll"
      )
    }
  }

  sourceSets {
    val sampleVideosPath = localProperties?.getProperty("sample.videos.dir")
    if (sampleVideosPath != null) {
      val sampleVideosDir = File(sampleVideosPath)
      if (sampleVideosDir.isDirectory) {
        getByName("androidTest").assets.directories.add(sampleVideosPath)
      }
    }
  }
}

dependencies {
  implementation(libs.androidx.activity.compose)
  implementation(platform(libs.androidx.compose.bom))
  implementation(libs.androidx.compose.material3)
  implementation(libs.androidx.navigation3.runtime)
  implementation(libs.androidx.navigation3.ui)
  implementation(libs.androidx.lifecycle.viewmodel.compose)
  implementation(project(":lib:video"))
  implementation(project(":core:util"))
  implementation(project(":core:ui"))
  implementation(libs.androidx.documentfile)
  implementation(libs.androidx.compose.ui.tooling.core)
  debugImplementation(libs.androidx.compose.ui.test.manifest)
  androidTestImplementation(testLibs.junit.junit)
  androidTestImplementation(testLibs.androidx.test.runner)
  androidTestImplementation(testLibs.androidx.test.ext.junit.ktx)
  androidTestUtil(testLibs.androidx.test.orchestrator)
}
