ext {
    lifecycle = '2.3.0'
    glide = "4.13.2"
    constraint_layout = '2.1.4'
    material = "1.3.0"
    fragment  = "1.5.0"
    activity = "1.2.0"
    recycler = "1.2.1"
    appCompat = "1.2.0"
    coreKTX = "1.5.0"

    //compilation
    compileVersion = 33
    minVersion = 21
    verCode = 1
    verName = "1.0.0"
    testRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildscript {
    ext.kotlin_version = '1.7.10'

    ext.compiledAppVersion = 33

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    group = "io.github.funkymuse"

    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}



subprojects {

    switch (it.name){
        case 'app':
            apply plugin: 'com.android.application'
            apply plugin: 'kotlin-android'
            apply plugin: 'kotlin-kapt'
            apply plugin: 'kotlin-parcelize'

            dependencies {
                implementation project(path: ':imagepicker')
                implementation project(path: ':videopicker')
                implementation project(path: ':audiopicker')
                implementation project(path: ':core')
            }

            break

        case 'core':

            apply plugin: 'com.android.library'
            apply plugin: 'kotlin-android'
            apply plugin: 'kotlin-parcelize'
            apply plugin: 'kotlin-kapt'
            apply plugin: 'maven-publish'


            dependencies {
                testImplementation 'junit:junit:4.13.2'
                androidTestImplementation 'androidx.test.ext:junit:1.1.3'
                androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

                //glide
                api "com.github.bumptech.glide:glide:$glide"
                kapt "com.github.bumptech.glide:compiler:$glide"

                //core
                api "androidx.activity:activity-ktx:$activity"
                api "androidx.fragment:fragment-ktx:$fragment"
                api "androidx.appcompat:appcompat:$appCompat"
                api "androidx.core:core-ktx:$coreKTX"

                //ui
                api "androidx.constraintlayout:constraintlayout:$constraint_layout"
                api "androidx.recyclerview:recyclerview:$recycler"
                api "com.google.android.material:material:$material"

                //live data
                api "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle"
                api "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle"
                api "androidx.lifecycle:lifecycle-common-java8:$lifecycle"
                api "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle"
            }

            it.afterEvaluate {
                publishing {
                    publications {
                        release(MavenPublication) {
                            from components.release
                        }
                    }
                }
            }

            break

        case 'extensions':


            apply plugin: 'com.android.library'
            apply plugin: 'kotlin-android'
            apply plugin: 'kotlin-parcelize'
            apply plugin: 'kotlin-kapt'
            apply plugin: 'maven-publish'

            dependencies {
                implementation project(path: ':core')
            }
            it.afterEvaluate {
                publishing {
                    publications {
                        release(MavenPublication) {
                            from components.release
                        }
                    }
                }
            }

            break

            default:

            apply plugin: 'com.android.library'
            apply plugin: 'kotlin-android'
            apply plugin: 'kotlin-parcelize'
            apply plugin: 'kotlin-kapt'
            apply plugin: 'maven-publish'

            dependencies {
                api project(path: ':core')
                implementation project(path: ':extensions')
            }

            it.afterEvaluate {
                publishing {
                    publications {
                        release(MavenPublication) {
                            from components.release
                        }
                    }
                }
            }

            break

    }

    android {
        compileSdkVersion compileVersion

        defaultConfig {
            minSdkVersion minVersion
            targetSdkVersion compileVersion
            versionCode verCode
            versionName verName
            testInstrumentationRunner testRunner
        }

        compileOptions {
            sourceCompatibility = 1.8
            targetCompatibility = 1.8
        }

        kotlinOptions {
            jvmTarget = "1.8"
        }

        buildFeatures {
            viewBinding = true
            aidl = false
            renderScript = false
            resValues = false
            shaders = false
            buildConfig = false
        }
    }
}
