package com.cm.common.pojo.bos;

import org.springframework.security.core.GrantedAuthority;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: RoleGrantedAuthority
 * @Description: 角色权限
 * @Author: WangGeng
 * @Date: 2019-06-08 10:34
 * @Version: 1.0
 **/
public class RoleGrantedAuthority implements GrantedAuthority {

    private static final long serialVersionUID = 520L;
    private String role;
    private String roleId;
    private String roleName;
    private List<RoleMenuBO> saveMenu;
    private List<RoleMenuBO> deleteMenu;
    private List<RoleMenuBO> updateMenu;
    private List<RoleMenuBO> queryMenu;
    private List<PermissionBO> permissionInsert;
    private List<PermissionBO> permissionDelete;
    private List<PermissionBO> permissionUpdate;
    private List<PermissionBO> permissionQuery;

    public RoleGrantedAuthority(String role) {
        this.role = role;
    }

    public RoleGrantedAuthority(String role, RoleBO roleBO) {
        this.role = role;
        this.roleId = roleBO.getRoleId();
        this.roleName = roleBO.getRoleName();
        this.saveMenu = roleBO.getSaveMenu();
        this.deleteMenu = roleBO.getDeleteMenu();
        this.updateMenu = roleBO.getUpdateMenu();
        this.queryMenu = roleBO.getQueryMenu();
        this.permissionInsert = roleBO.getPermissionInsert();
        this.permissionDelete = roleBO.getPermissionDelete();
        this.permissionUpdate = roleBO.getPermissionUpdate();
        this.permissionQuery = roleBO.getPermissionQuery();
    }

    @Override
    public String getAuthority() {
        return this.role;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else {
            return obj instanceof RoleGrantedAuthority ? this.role.equals(((RoleGrantedAuthority) obj).role) : false;
        }
    }

    @Override
    public int hashCode() {
        return this.role.hashCode();
    }

    public String getRoleId() {
        return roleId == null ? "" : roleId.trim();
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public String getRoleName() {
        return roleName == null ? "" : roleName.trim();
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public List<RoleMenuBO> getSaveMenu() {
        return saveMenu == null ? new ArrayList() : saveMenu;
    }

    public void setSaveMenu(List<RoleMenuBO> saveMenu) {
        this.saveMenu = saveMenu;
    }

    public List<RoleMenuBO> getDeleteMenu() {
        return deleteMenu == null ? new ArrayList() : deleteMenu;
    }

    public void setDeleteMenu(List<RoleMenuBO> deleteMenu) {
        this.deleteMenu = deleteMenu;
    }

    public List<RoleMenuBO> getUpdateMenu() {
        return updateMenu == null ? new ArrayList() : updateMenu;
    }

    public void setUpdateMenu(List<RoleMenuBO> updateMenu) {
        this.updateMenu = updateMenu;
    }

    public List<RoleMenuBO> getQueryMenu() {
        return queryMenu == null ? new ArrayList() : queryMenu;
    }

    public void setQueryMenu(List<RoleMenuBO> queryMenu) {
        this.queryMenu = queryMenu;
    }

    public List<PermissionBO> getPermissionInsert() {
        return permissionInsert;
    }

    public void setPermissionInsert(List<PermissionBO> permissionInsert) {
        this.permissionInsert = permissionInsert;
    }

    public List<PermissionBO> getPermissionDelete() {
        return permissionDelete;
    }

    public void setPermissionDelete(List<PermissionBO> permissionDelete) {
        this.permissionDelete = permissionDelete;
    }

    public List<PermissionBO> getPermissionUpdate() {
        return permissionUpdate;
    }

    public void setPermissionUpdate(List<PermissionBO> permissionUpdate) {
        this.permissionUpdate = permissionUpdate;
    }

    public List<PermissionBO> getPermissionQuery() {
        return permissionQuery;
    }

    public void setPermissionQuery(List<PermissionBO> permissionQuery) {
        this.permissionQuery = permissionQuery;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"role\":\"")
                .append(role).append('\"');
        sb.append(",\"roleId\":\"")
                .append(roleId).append('\"');
        sb.append(",\"roleName\":\"")
                .append(roleName).append('\"');
        sb.append(",\"saveMenu\":")
                .append(saveMenu);
        sb.append(",\"deleteMenu\":")
                .append(deleteMenu);
        sb.append(",\"updateMenu\":")
                .append(updateMenu);
        sb.append(",\"queryMenu\":")
                .append(queryMenu);
        sb.append(",\"permissionInsert\":")
                .append(permissionInsert);
        sb.append(",\"permissionDelete\":")
                .append(permissionDelete);
        sb.append(",\"permissionUpdate\":")
                .append(permissionUpdate);
        sb.append(",\"permissionQuery\":")
                .append(permissionQuery);
        sb.append('}');
        return sb.toString();
    }
}
