plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'maven-publish'
    id 'kotlin-parcelize'
    id 'androidx.navigation.safeargs.kotlin'
    id 'signing'
    id "org.jetbrains.dokka" version "1.5.0"
}
def getVersionName = { ->
    return "$HMS_ROOM_KIT_VERSION"
}

android {
    namespace 'live.hms.roomkit'
    compileSdk 34

    defaultConfig {
        minSdkVersion 21
        targetSdk 34
        versionCode 1
        versionName getVersionName()

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"

        buildConfigField "boolean", "INTERNAL", project.findProperty('INTERNAL') ? INTERNAL : "false"
        buildConfigField "String", "BUG_REPORT_EMAIL_TO", project.findProperty('BUG_REPORT_EMAIL_TO') ? BUG_REPORT_EMAIL_TO : "\"\""
        buildConfigField "String", "BUG_REPORT_EMAIL_CC", project.findProperty('BUG_REPORT_EMAIL_CC') ? BUG_REPORT_EMAIL_CC : "\"\""
        buildConfigField "String", "RTMP_INJEST_URL", project.findProperty('RTMP_INJEST_URL') ? RTMP_INJEST_URL : "\"\""

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }

    buildFeatures {
        viewBinding true
        dataBinding true
        compose true
        buildConfig = true
    }
    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.8"
    }

    publishing {
        singleVariant('release') {
            withSourcesJar()
        }
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.10.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'
    implementation "com.otaliastudios:zoomlayout:1.9.0"
    implementation project(":prebuilt-themes")
    implementation project(":vb-prebuilt")
    // To add dependencies of specific module
    implementation "live.100ms:android-sdk:$HMS_SDK_VERSION"
    implementation "live.100ms:video-view:$HMS_SDK_VERSION"
    implementation "live.100ms:hls-player:$HMS_SDK_VERSION"
//    implementation "live.100ms:video-filters:$HMS_SDK_VERSION"
    // allows the api to be present so the [HMsVirtualBackgroundInjector] can add the real
    // class when it is included but also allows the fake one to be injected when
    // the import is not added. This saves 26Mb from being added to every prebuilt user.
    compileOnly "live.100ms:virtual-background:$HMS_SDK_VERSION"

    // Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.7.4"
    implementation "androidx.navigation:navigation-ui-ktx:2.7.4"

    implementation "androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03"

    // Life Cycle
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.6.2"
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.google.code.gson:gson:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    // Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
    implementation 'com.github.bumptech.glide:glide:4.15.1'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    def groupieVersion = "2.10.1"
    implementation "live.100ms.groupie:groupie:$groupieVersion"
    implementation "live.100ms.groupie:groupie-viewbinding:$groupieVersion"


    def composeBom = platform('androidx.compose:compose-bom:2023.10.01')
    implementation composeBom
    // Material Design 3
    implementation 'androidx.compose.material3:material3'
    implementation 'androidx.compose.foundation:foundation'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    debugImplementation 'androidx.compose.ui:ui-tooling'
// UI Tests
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
    debugImplementation 'androidx.compose.ui:ui-test-manifest'
// Optional - Integration with ViewModels
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1'
    // Optional - Integration with LiveData
    implementation "androidx.compose.ui:ui-viewbinding:1.3.2"
    implementation 'androidx.compose.runtime:runtime-livedata'
    implementation "com.github.bumptech.glide:compose:1.0.0-beta01"

}

task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
    archiveFileName = "javadoc.jar"
    from "build/dokka/javadoc"
    archiveClassifier.set("javadoc")
}

afterEvaluate {
    publishing {
        publications {
            // Creates a Maven publication called "release".
            release(MavenPublication) {
                from components.release
                
                // Only sign the artefacts if this is a maven central build.
                // This would only halt jitpack builds and/or make our signing keys public.
                if(rootProject.properties["ossrhUsername"]) {
                    artifact javadocJar
                }
                
                pom {
                    name = "100ms.live Android Room Kit"
                    description = "Room Kit that simplifies setting up videoconferencing in your own app. See more at https://www.100ms.live/docs/android/v2/guides/quickstart"
                    url = "100ms.live"
                    licenses {
                        license {
                            name = 'MIT License'
                            url = 'http://www.opensource.org/licenses/mit-license.php'
                        }
                    }
                    developers {
                        developer {
                            id = '1'
                            name = '100ms'
                            email = 'support@100ms.live'
                        }
                    }
                    scm {
                        connection = 'SCM is private'
                        developerConnection = 'SCM is private'
                        url = 'https://github.com/100mslive/100ms-android'
                    }
                }
                groupId = "live.100ms"
                artifactId = 'room-kit'
                version = getVersionName()
            }
        }
    }

    if(rootProject.properties["ossrhUsername"]) {
        signing {
            sign publishing.publications
        }
    }
}
