package com.zsc.edu.gateway.modules.system.vo;

import com.zsc.edu.gateway.modules.system.entity.Menu;
import lombok.Data;

import java.util.List;

/**
 * 菜单
 *
 * @author harry yao
 */
@Data
public class MenuVo {
    /**
     * 菜单id
     */
    private Long id;
    /**
     * 父菜单id
     */
    private Long pid;
    /**
     * 路由名称
     */
    private String name;
    /**
     * 菜单路径
     */
    private String path;

    private Meta meta;

    /**
     * 子菜单
     */
    private List<MenuVo> children = null;

    public MenuVo(Menu menu) {
        this.id = menu.getId();
        this.pid = menu.getPid();
        this.name = menu.getName();
        this.path = menu.getPath();
        this.meta = new Meta(menu);
    }
}
@Data
class Meta {
    /**
     * 菜单名称（语言包键名）
     */
    private String locale;
    /**
     * 菜单icon
     */
    private String icon;
    /**
     * 是否需要登录鉴权
     */
    private Boolean requiresAuth;
    /**
     * 是否隐藏菜单
     */
    private Boolean hideInMenu;
    /**
     * 排序
     */
    private Integer order;
    /**
     * 访问权限，使用","隔开的权限字符串
     */
    private String[] permissions;

    public Meta(Menu menu) {
        this.locale = menu.getLocale();
        this.icon = menu.getIcon();
        this.requiresAuth = menu.getRequiresAuth();
        this.hideInMenu = menu.getHideInMenu();
        this.order = menu.getMenuOrder();
        this.permissions = menu.getPermissions().split(",");
    }
}