/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-parcelize"

// Safe args allows the passing of data in bundles with type safety
// See more at https://developer.android.com/guide/navigation/navigation-pass-data
apply plugin: "androidx.navigation.safeargs.kotlin"

// Allows for Kotlin annotation processors
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 32
    defaultConfig {
        applicationId "com.android.tv.reference"
        minSdkVersion 23
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testOptions.unitTests.includeAndroidResources = true

        // When true, the app will display features that require Firebase to be configured
        // such as the ability to create a user account. When false, those features are hidden,
        // there is no user account, and watch progress is stored locally.
        buildConfigField("boolean", "FIREBASE_ENABLED", "false")
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        // View binding allows efficient, type-safe view access
        // See more at https://developer.android.com/topic/libraries/view-binding
        viewBinding = true
    }

    compileOptions {
        // Desugaring enables using Java 8 APIs like java.time in a backwards compatible manner.
        coreLibraryDesugaringEnabled true
        // Exoplayer requires targeting Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

    // AndroidX libraries
    def leanback_version = "1.2.0-alpha02"
    def room_version = "2.4.2"
    def fragment_version = "1.4.1"
    def cast_tv_version = "17.0.0"
    def cast_version = "19.0.0"
    implementation "androidx.appcompat:appcompat:1.4.1"
    implementation "androidx.core:core-ktx:1.7.0"
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "androidx.leanback:leanback:$leanback_version"
    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    implementation "androidx.preference:preference-ktx:1.2.0"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"

    // Cast library used for Cast Connect feature
    implementation "com.google.android.gms:play-services-cast-tv:$cast_tv_version"
    implementation "com.google.android.gms:play-services-cast:$cast_version"

    debugImplementation "androidx.fragment:fragment-testing:$fragment_version"

    // Work library used for simplifying work done in the background
    def work_version = "2.7.1"
    implementation "androidx.work:work-runtime:$work_version"

    // TV provider library used for updating home screen channels
    implementation 'androidx.tvprovider:tvprovider:1.0.0'

    // Picasso for image loading
    implementation 'com.squareup.picasso:picasso:2.71828'

    // Exoplayer for playback
    def exoplayer_version = "2.17.1"
    implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
    implementation "com.google.android.exoplayer:extension-leanback:$exoplayer_version"
    implementation "com.google.android.exoplayer:extension-mediasession:$exoplayer_version"

    // Google Play Services for identity
    def playservices_version = "20.1.0"
    implementation "com.google.android.gms:play-services-auth:$playservices_version"

    // Moshi for JSON parsing
    implementation("com.squareup.moshi:moshi-kotlin:1.13.0")
    kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")

    // Retrofit for HTTP requests
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'

    // Logging
    implementation("com.jakewharton.timber:timber:5.0.1")

    // Testing libraries
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'android.arch.core:core-testing:1.1.1'
    testImplementation "androidx.room:room-testing:$room_version"
    testImplementation 'androidx.test:core:1.4.0'
    testImplementation 'androidx.test:rules:1.4.0'
    testImplementation 'androidx.test:runner:1.4.0'
    testImplementation 'androidx.test.ext:junit:1.1.3'
    testImplementation "androidx.work:work-testing:$work_version"
    testImplementation "com.google.truth:truth:1.1.3"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0-native-mt"
    testImplementation "org.mockito:mockito-core:4.4.0"
    testImplementation 'org.mockito:mockito-inline:4.4.0'
    testImplementation 'org.robolectric:robolectric:4.7.3'
}
