package com.cool.store.vo.role;

import com.cool.store.entity.SysRoleDO;
import com.cool.store.entity.SysRoleMenuDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.ListUtils;

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

/**
 * @author zhangchenbiao
 * @FileName: RoleAuthInfoVO
 * @Description:
 * @date 2023-07-25 15:11
 */
@Data
public class RoleAuthInfoVO {

    @ApiModelProperty("角色id")
    private String roleId;

    @ApiModelProperty("角色名称")
    private String roleName;

    @ApiModelProperty("菜单ids")
    private List<Long> menuIds;

    public static RoleAuthInfoVO convertVO(SysRoleDO role, List<SysRoleMenuDO> roleMenuList){
        if(Objects.isNull(role)){
            return null;
        }
        RoleAuthInfoVO result = new RoleAuthInfoVO();
        result.setRoleId(role.getRoleId());
        result.setRoleName(role.getRoleName());
        result.setMenuIds(ListUtils.emptyIfNull(roleMenuList).stream().map(SysRoleMenuDO::getMenuId).distinct().collect(Collectors.toList()));
        return result;
    }

}
