package com.cm.common.pojo.bos;

import org.springframework.security.core.GrantedAuthority;

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> apiSaveMenu;
    private List<RoleMenuBO> apiDeleteMenu;
    private List<RoleMenuBO> apiUpdateMenu;
    private List<RoleMenuBO> apiQueryMenu;
    private List<RoleMenuBO> resourceSaveMenu;
    private List<RoleMenuBO> resourceDeleteMenu;
    private List<RoleMenuBO> resourceUpdateMenu;
    private List<RoleMenuBO> resourceQueryMenu;
    private List<RoleMenuBO> routeSaveMenu;
    private List<RoleMenuBO> routeUpdateMenu;
    private List<RoleMenuBO> routeQueryMenu;
    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.apiSaveMenu = roleBO.getApiSaveMenu();
        this.apiDeleteMenu = roleBO.getApiDeleteMenu();
        this.apiUpdateMenu = roleBO.getApiUpdateMenu();
        this.apiQueryMenu = roleBO.getApiQueryMenu();
        this.resourceSaveMenu = roleBO.getResourceSaveMenu();
        this.resourceDeleteMenu = roleBO.getResourceDeleteMenu();
        this.resourceUpdateMenu = roleBO.getResourceUpdateMenu();
        this.resourceQueryMenu = roleBO.getResourceQueryMenu();
        this.routeSaveMenu = roleBO.getRouteSaveMenu();
        this.routeUpdateMenu = roleBO.getRouteUpdateMenu();
        this.routeQueryMenu = roleBO.getRouteQueryMenu();
        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> getApiSaveMenu() {
        return apiSaveMenu;
    }

    public void setApiSaveMenu(List<RoleMenuBO> apiSaveMenu) {
        this.apiSaveMenu = apiSaveMenu;
    }

    public List<RoleMenuBO> getApiDeleteMenu() {
        return apiDeleteMenu;
    }

    public void setApiDeleteMenu(List<RoleMenuBO> apiDeleteMenu) {
        this.apiDeleteMenu = apiDeleteMenu;
    }

    public List<RoleMenuBO> getApiUpdateMenu() {
        return apiUpdateMenu;
    }

    public void setApiUpdateMenu(List<RoleMenuBO> apiUpdateMenu) {
        this.apiUpdateMenu = apiUpdateMenu;
    }

    public List<RoleMenuBO> getApiQueryMenu() {
        return apiQueryMenu;
    }

    public void setApiQueryMenu(List<RoleMenuBO> apiQueryMenu) {
        this.apiQueryMenu = apiQueryMenu;
    }

    public List<RoleMenuBO> getResourceSaveMenu() {
        return resourceSaveMenu;
    }

    public void setResourceSaveMenu(List<RoleMenuBO> resourceSaveMenu) {
        this.resourceSaveMenu = resourceSaveMenu;
    }

    public List<RoleMenuBO> getResourceDeleteMenu() {
        return resourceDeleteMenu;
    }

    public void setResourceDeleteMenu(List<RoleMenuBO> resourceDeleteMenu) {
        this.resourceDeleteMenu = resourceDeleteMenu;
    }

    public List<RoleMenuBO> getResourceUpdateMenu() {
        return resourceUpdateMenu;
    }

    public void setResourceUpdateMenu(List<RoleMenuBO> resourceUpdateMenu) {
        this.resourceUpdateMenu = resourceUpdateMenu;
    }

    public List<RoleMenuBO> getResourceQueryMenu() {
        return resourceQueryMenu;
    }

    public void setResourceQueryMenu(List<RoleMenuBO> resourceQueryMenu) {
        this.resourceQueryMenu = resourceQueryMenu;
    }

    public List<RoleMenuBO> getRouteSaveMenu() {
        return routeSaveMenu;
    }

    public void setRouteSaveMenu(List<RoleMenuBO> routeSaveMenu) {
        this.routeSaveMenu = routeSaveMenu;
    }

    public List<RoleMenuBO> getRouteUpdateMenu() {
        return routeUpdateMenu;
    }

    public void setRouteUpdateMenu(List<RoleMenuBO> routeUpdateMenu) {
        this.routeUpdateMenu = routeUpdateMenu;
    }

    public List<RoleMenuBO> getRouteQueryMenu() {
        return routeQueryMenu;
    }

    public void setRouteQueryMenu(List<RoleMenuBO> routeQueryMenu) {
        this.routeQueryMenu = routeQueryMenu;
    }

    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("\"").append(role).append("\"");
        sb.append(",\"roleId\":")
                .append("\"").append(roleId).append("\"");
        sb.append(",\"roleName\":")
                .append("\"").append(roleName).append("\"");
        sb.append(",\"apiSaveMenu\":")
                .append(apiSaveMenu);
        sb.append(",\"apiDeleteMenu\":")
                .append(apiDeleteMenu);
        sb.append(",\"apiUpdateMenu\":")
                .append(apiUpdateMenu);
        sb.append(",\"apiQueryMenu\":")
                .append(apiQueryMenu);
        sb.append(",\"resourceSaveMenu\":")
                .append(resourceSaveMenu);
        sb.append(",\"resourceDeleteMenu\":")
                .append(resourceDeleteMenu);
        sb.append(",\"resourceUpdateMenu\":")
                .append(resourceUpdateMenu);
        sb.append(",\"resourceQueryMenu\":")
                .append(resourceQueryMenu);
        sb.append(",\"routeSaveMenu\":")
                .append(routeSaveMenu);
        sb.append(",\"routeUpdateMenu\":")
                .append(routeUpdateMenu);
        sb.append(",\"routeQueryMenu\":")
                .append(routeQueryMenu);
        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();
    }
}
