// 不启用可选模块，默认启用需手动开启
gradle.ext.excludeOptionalModules
        = gradle.startParameter.projectProperties.get('EXCLUDE_OPTIONAL_MODULES')?.toBoolean() ?: false

// 当 excludeOptionalModule 为 true 时，需要手动 enable 需要用到的 module
gradle.ext.enablePkg = gradle.startParameter.projectProperties.get('ENABLE_PKG')?.toBoolean() ?: false
gradle.ext.enableFeedback = gradle.startParameter.projectProperties.get('ENABLE_FEEDBACK')?.toBoolean() ?: false
gradle.ext.enableMessage = gradle.startParameter.projectProperties.get('ENABLE_MESSAGE')?.toBoolean() ?: false
gradle.ext.enableOaid = gradle.startParameter.projectProperties.get('ENABLE_OAID')?.toBoolean() ?: false
gradle.ext.enableFloatingWindow = gradle.startParameter.projectProperties.get('ENABLE_FLOATING_WINDOW')?.toBoolean() ?: false
gradle.ext.enableSensorData = gradle.startParameter.projectProperties.get('ENABLE_SENSOR_DATA')?.toBoolean() ?: false
gradle.ext.enableCsjAd = gradle.startParameter.projectProperties.get('ENABLE_CSJ_AD')?.toBoolean() ?: false
gradle.ext.enableQQGame = gradle.startParameter.projectProperties.get('ENABLE_QQ_GAME')?.toBoolean() ?: false
gradle.ext.enablePush = gradle.startParameter.projectProperties.get('ENABLE_PUSH')?.toBoolean() ?: false
gradle.ext.enableSentry = gradle.startParameter.projectProperties.get('ENABLE_SENTRY')?.toBoolean() ?: false
gradle.ext.enableVa = gradle.startParameter.projectProperties.get('ENABLE_VA')?.toBoolean() ?: false
gradle.ext.enableQuickLogin = gradle.startParameter.projectProperties.get('ENABLE_QUICK_LOGIN')?.toBoolean() ?: false
gradle.ext.enableAccelerator = gradle.startParameter.projectProperties.get('ENABLE_ACCELERATOR')?.toBoolean() ?: false
gradle.ext.enableWechatPay = gradle.startParameter.projectProperties.get('ENABLE_WECHAT_PAY')?.toBoolean() ?: false
gradle.ext.enableAliPay = gradle.startParameter.projectProperties.get('ENABLE_ALI_PAY')?.toBoolean() ?: false

// 是否启用路由文档输出
gradle.ext.enableRouteDoc = gradle.startParameter.projectProperties.get('ENABLE_ROUTE_DOC')?.toBoolean() ?: false

// 核心模块
def coreModules = [
        ':app',
        ':module_core',
        ':module_common',
        ':module_login',
        ':module_setting',
//        ':module_setting_compose',
        ':ndownload',
        ':module_core_feature',
        ':libraries:LGLibrary',
        ':libraries:QQShare',
        ':libraries:Matisse',
        ':vspace-bridge:vspace',
        ':feature:xapk-installer',
        ':feature:media_select',
        ':feature:route_doc',
        ':module_internal_test',
        ':module_va_api',
]

// 定义 va 核心模块
// key: 模块名, value: 目录名
def vaCoreModule = [
        'va-archive-common': 'vasdk/archive_common'
]

// 可选是否启用的模块
def optionalModules = [
        ':feature:pkg',
        ':feature:floating-window',
        ':feature:csj_ad',
        ':feature:oaid_lib',
        ':feature:oaid',
        ':feature:new_feedback',
        ':feature:qq_game',
        ':feature:jg_push',
        ':feature:jg_push_lib',
        ':feature:acloud_push',
        ':feature:sentry',
        ':feature:quick_login',
        ':feature:accelerator',
        ':feature:wechat_pay',
        ':feature:ali_pay',
        ':module_message',
        ':module_sensors_data',
        ':module_va_impl'
]

// 定义 va 可选模块
def optionalVaModules = [
        'va-main'            : 'vasdk/app',
        'va-lib'             : 'vasdk/lib',
        'va-lib-res'         : 'vasdk/lib-res',
        'va-common'          : 'vasdk/common',
        'va-core'            : 'vasdk/core',
        'va-feature-realname': 'vasdk/feature/realname-window',
        'va-feature-translate': 'vasdk/feature/translate',
        'va-library-commons' : 'vasdk/commons',
        'va-library-network' : 'vasdk/library/network',
        'va-archive'         : 'vasdk/archive',
        'va-plugin-constant' : 'vasdk/plugin/constant',
        'va-plugin-host'     : 'vasdk/host',
        'va-plugin-host-lib' : 'vasdk/plugin/host-lib',
        'va-sandhook'        : 'vasdk/sandhook'
]

def includeVaModuleFun(Map<String, String> vaModules) {
    vaModules.each { moduleName, pathName ->
        include moduleName
        project(":$moduleName").projectDir = file(pathName)
    }
}

// 包含core必选模块
for (String module : coreModules) {
    include module
}
// 包含va必选模块
includeVaModuleFun(vaCoreModule)


if (gradle.ext.excludeOptionalModules == false) { // 默认全部模块都包含
    // 包含可选模块
    for (String module : optionalModules) {
        include module
    }
    // 包含va可选模块
    optionalVaModules.each { moduleName, pathName ->
        include moduleName
        project(":$moduleName").projectDir = file(pathName)
    }
} else {
    if (gradle.ext.enablePkg) {
        include ':feature:pkg'
    }
    if (gradle.ext.enableFeedback) {
        include ':feature:new_feedback'
    }
    if (gradle.ext.enableMessage) {
        include ':module_message'
    }
    if (gradle.ext.enableOaid) {
        include ':feature:oaid'
        include ':feature:oaid_lib'
    }
    if (gradle.ext.enableFloatingWindow) {
        include ':feature:floating-window'
    }
    if (gradle.ext.enableSensorData) {
        include ':module_sensors_data'
    }
    if (gradle.ext.enableCsjAd) {
        include ':feature:csj_ad'
    }
    if (gradle.ext.enableQQGame) {
        include ':feature:qq_game'
    }
    if (gradle.ext.enablePush) {
        include ':feature:jg_push'
        include ':feature:jg_push_lib'
        include ':feature:acloud_push'
    }
    if (gradle.ext.enableSentry) {
        include ':feature:sentry'
    }
    if (gradle.ext.enableVa) {
        include ':module_va_impl'
        // 包含 va 可选模块
        includeVaModuleFun(optionalVaModules)
    }
    if (gradle.ext.enableQuickLogin) {
        include(':feature:quick_login')
    }
    if (gradle.ext.enableAccelerator) {
        include ':feature:accelerator'
    }
    if (gradle.ext.enableWechatPay) {
        include ':feature:wechat_pay'
    }
    if (gradle.ext.enableAliPay) {
        include ':feature:ali_pay'
    }
}
