/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 */

apply plugin: 'com.android.application'

android {
    //the compression of webp file during build causes problem with FileDescriptor in ContentProvider.
    aaptOptions {
        noCompress "webp"
    }
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.example.samplestickerapp"
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        def contentProviderAuthority = applicationId + ".stickercontentprovider"
        def remoteContentProviderAuthority = applicationId + ".remotestickercontentprovider"
        // Creates a placeholder property to use in the manifest.
        manifestPlaceholders =
                [contentProviderAuthority: contentProviderAuthority,
                 remoteContentProviderAuthority: remoteContentProviderAuthority]
        // Adds a new field for the authority to the BuildConfig class.
        buildConfigField("String",
                "CONTENT_PROVIDER_AUTHORITY",
                "\"${contentProviderAuthority}\"")
        buildConfigField("String",
                "REMOTE_CONTENT_PROVIDER_AUTHORITY",
                "\"${remoteContentProviderAuthority}\"")
    }
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

    packagingOptions {
        exclude 'lib/*/libnative-imagetranscoder.so'
        exclude 'lib/*/libnative-filters.so'
    }
    namespace 'com.example.samplestickerapp'

    // Configures multiple APKs based on ABI.
    // see https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
//    splits {
//        abi {
//            enable true // Enables building multiple APKs per ABI.
//            universalApk true // Specifies that we want to also generate a universal APK that includes all ABIs.
//        }
//    }
}

task checkDebug {
    doLast {
        println("checkDebug")
        if (android.defaultConfig.applicationId.startsWith("com.whatsapp")) {
            throw new GradleException("applicationId in defaultConfig cannot start with com.whatsapp, please change your applicationId in app/build.gradle")
        }
        checkApplicationIdInDebug()
    }
}

private void checkApplicationIdInDebug() {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ignoreApplicationIdCheck = properties.getProperty('ignoreApplicationIdCheck')
    if (ignoreApplicationIdCheck == null) {
        if (android.defaultConfig.applicationId == "com.example.samplestickerapp") {
            throw new GradleException("Your applicationId is currently com.example.samplestickerapp, please change your applicationId to a different string in app/build.gradle in line 10")
        }
    } else {
        println("application id check ignored")
    }
}


task checkRelease {
    doLast {
        println("checkRelease")
        if (android.defaultConfig.applicationId.startsWith("com.example")) {
            throw new GradleException("applicationId in defaultConfig cannot start with com.example, please change your applicationId in app/build.gradle")
        }
    }
}

tasks.whenTaskAdded { task ->
    println(task.name)
    if (task.name.contains("assembleDebug")) {
        task.dependsOn checkDebug
    }
    if (task.name.contains("assembleRelease")) {
        task.dependsOn checkRelease
    }
}


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    def fresco_version = '2.5.0'
    implementation "com.facebook.fresco:fresco:$fresco_version"
    implementation "com.facebook.fresco:webpsupport:$fresco_version"
    implementation "com.facebook.fresco:animated-webp:$fresco_version"
    implementation "com.facebook.fresco:animated-base:$fresco_version"

    // --- Adicionado para integração com o servidor (StickerHub API) ---
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
    implementation 'org.json:json:20231013'
    implementation 'androidx.activity:activity:1.6.1'
}
