package gaf3.core.services.menu.entity

import com.fasterxml.jackson.annotation.JsonInclude
import gaf3.core.jpa.GafTimestamp
import javax.persistence.*
import java.io.Serializable
import java.util.*
import kotlin.jvm.Transient


/**
 * 扁平化的菜单项数据
 * The persistent class for the GAF_MENU_ITEM database table.
 *
 */
@Entity
@Table(name = "GAF_MENU_ITEM")
@JsonInclude(JsonInclude.Include.NON_NULL)
class GafMenuItem {

    /**
     * 菜单项ID，随机生成的UUID
     */
    @Id
    @Column(name = "ID", length = 48)
    var id: String? = null

    /**
     * 菜单项上级ID，根菜单为'00000000-0000-0000-0000-000000000000'
     */
    @Column(name = "PID", length = 48)
    var pid: String? = null

    /**
     * 所属应用模块，仅当根级菜单有效
     * 用于分组过滤菜单树节点
     */
    @Column(name = "MODULE", length = 48)
    var module: String? = null

    /**
     * 菜单显示模式，仅当根级菜单有效
     * 可选值有：
     *      0 - 仅在树状菜单中显示，默认
     *      1 - 仅在横向导航条菜单中显示
     *      2 - 双模式
     */
    @Column(name = "MODE", length = 48)
    var mode: String? = null

    /**
     * 显示名称
     */
    @Column(name = "TITLE", length = 48)
    var title: String? = null

    /**
     * 显示图标（css样式类）
     */
    @Column(name = "ICON", length = 48)
    var icon: String? = null

    /**
     * 路由地址，SPA内部跳转
     * path和（url，target）二选一，优先使用path，即path有效时（url，target）忽略
     */
    @Column(name = "PATH")
    var path: String? = null

    /**
     * 跳转地址
     * URL链接或SPA内部路由地址，与target配合使用
     */
    @Column(name = "url")
    var url: String? = null

    /**
     * 跳转页面打开方式，对应html中<a>标签的target属性
     */
    @Column(name = "TARGET", length = 48)
    var target: String? = null

    /**
     * 菜单可见性
     */
    @Column(name = "VISIBLE")
    var visible: Boolean? = null

    /**
     * 预置数据标记： 0-否，1-是，系统预设值不可删除
     */
    @Column(name = "PRESET")
    var preset: Int? = null

    /**
     * 排序字段
     */
    @Column(name = "RANKING")
    var ranking: Long? = null

    /**
     * 备注信息
     */
    @Column(name = "REMARK")
    var remark: String? = null

    @PrePersist
    fun insertRank() {
        ranking = Calendar.getInstance().timeInMillis
    }

    companion object {
        private const val serialVersionUID = 1L
    }

}