/*
 * Copyright 2019-2020 Mamoe Technologies and contributors.
 *
 * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
 * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link.
 *
 * https://github.com/mamoe/mirai/blob/master/LICENSE
 */

@file:Suppress("PRE_RELEASE_CLASS")

package net.mamoe.mirai.console.codegen.old

/**
 * used to generate Java PluginData
 */


open class JClazz(val primitiveName: String, val packageName: String) {
    open val funName: String = "value"
}

class JListClazz(item: JClazz) : JClazz("List<${item.packageName}>", "List<${item.packageName}>") {
    override val funName = item.primitiveName.toLowerCase() + "List"
}

class JArrayClazz(item: JClazz) : JClazz(item.primitiveName + "[]", item.primitiveName + "[]")

class JMapClazz(key: JClazz, value: JClazz) :
    JClazz("Map<${key.packageName},${value.packageName}>", "Map<${key.packageName},${value.packageName}>")


internal val J_NUMBERS = listOf(
    JClazz("int", "Integer"),
    JClazz("short", "Short"),
    JClazz("byte", "Byte"),
    JClazz("long", "Long"),
    JClazz("float", "Float"),
    JClazz("double", "Double")
)

internal val J_EXTRA = listOf(
    JClazz("String", "String"),
    JClazz("boolean", "Boolean"),
    JClazz("char", "Char")
)


fun JClazz.getTemplate(): String = """
        @NotNull default Value<${this.packageName}> $funName(${this.primitiveName} defaultValue){
            return _PluginDataKt.value(this,defaultValue);
        }
    """


fun main() {
    println(buildString {
        appendLine(COPYRIGHT)
        appendLine()
        appendLine(FILE_SUPPRESS)
        appendLine()
        appendLine(
            "/**\n" +
                    " * !!! This file is auto-generated by backend/codegen/src/kotlin/net.mamoe.mirai.console.codegen.JPluginDataCodegen.kt\n" +
                    " * !!! DO NOT MODIFY THIS FILE MANUALLY\n" +
                    " */\n" +
                    "\"\"\""
        )
        appendLine()
        appendLine()


        //do simplest
        (J_EXTRA + J_NUMBERS).forEach {
            appendLine(it.getTemplate())
        }

        (J_EXTRA + J_NUMBERS).forEach {
            appendLine(JListClazz(it).getTemplate())
        }

        (J_EXTRA + J_NUMBERS).forEach {
            appendLine(JArrayClazz(it).getTemplate())
        }

        (J_EXTRA + J_NUMBERS).forEach { key ->
            (J_EXTRA + J_NUMBERS).forEach { value ->
                appendLine(JMapClazz(key, value).getTemplate())
            }
        }
    })
}