package com.storlead.system.pojo.vo;

import com.storlead.system.pojo.entity.MenuEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @program: sp-sales
 * @description:
 * @author: chenkq
 * @create: 2022-06-29 11:06
 */
@Data
public class UserMenuVO extends MenuEntity {

    @ApiModelProperty(value = "子节点")
    private List<UserMenuVO> children;

    private String title;

    @ApiModelProperty(value = "弹窗类型：0：路径打开，2：当前页面弹窗")
    private Integer openType;

    private String getTitle(){
        return this.getMenuName();
    }

    /**
     * List<menu> 转为 List<UserMenuVO>
     * @param menus
     * @return
     */
    public static List<UserMenuVO> menuListToTargetMenuTreeVoList(List<MenuEntity> menus) {
        if (CollectionUtils.isEmpty(menus)) {
            return null;
        }
        List<UserMenuVO> menuVOS = menus.stream().map(UserMenuVO::menuToTargetMenuVo).filter(obj -> !Objects.isNull(obj)).collect(Collectors.toList());
        return menuVOS;
    }

    public static UserMenuVO  menuToTargetMenuVo(MenuEntity menu) {
        if (null == menu) {
            return null;
        }
        UserMenuVO menuVO = new UserMenuVO();
        BeanUtils.copyProperties(menu,menuVO);
        return menuVO;
    }

}
