package com.wisewoods.base.bean;


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

public class LoginUser extends Results {

    public UserBean user;
    public List<String> permissions;
    public List<String> roles;

    public static class UserBean {
        public boolean admin = false;
        public String avatar = "";
        public String createBy = "";
        public String createTime = "";
        public String delFlag = "";
        public long deptId;
        public DeptBean dept;
        public String email = "";
        public String loginDate = "";
        public String loginIp = "";
        public String nickName = "";
        public Object params;
        public String password = "";
        public String phonenumber = "";
        public String remark = "";
        public List<RoleBean> roles;

        public String sex = "";
        public String status = "";
        public long userId;
        public String userName = "";

        public int roleIndex;

        public List<CharSequence> getRolesStr() {
            List<CharSequence> rolesStr = new ArrayList<>();
            if (this.roles != null) {
                for (RoleBean role : this.roles) {
                    rolesStr.add(role.roleName);
                }
            }
            return rolesStr;
        }

        public List<Role> getRoles() {
            List<Role> roles = new ArrayList<>();
            if (this.roles != null) {
                for (RoleBean role : this.roles) {
                    switch (role.roleKey) {
                        case "teacher":
                            roles.add(Role.TEACHER);
                            break;
                        case "base":
                            roles.add(Role.BASE);
                            break;
                        case "organizer":
                            roles.add(Role.ORGANIZER);
                            break;
                        case "undertaker":
                            roles.add(Role.UNDERTAKER);
                            break;
                        case "education":
                            roles.add(Role.EDUCATION);
                            break;
                        case "train":
                        case "train_putong":
                            roles.add(Role.TRAIN);
                            break;
                        case "logistics":
                            roles.add(Role.LOGISTICS);
                            break;
                        default:
                            roles.add(Role.NONE);
                            break;
                    }
                }
            }
            return roles;
        }

        public Role getRole() {
            List<Role> roles = getRoles();
            if (roles.size() > 0 && roleIndex < roles.size()) {
                if (roleIndex >= roles.size()) {
                    roleIndex = 0;
                }
                return roles.get(roleIndex);
            }
            return Role.NONE;
        }
    }


    public static class DeptBean {
        public List<String> children;
        public long deptId;
        public String deptName = "";
        public String leader = "";
        public String orderNum = "";
        public Object params;
        public long parentId;
        public String status;
    }

    public static class RoleBean {
        public boolean admin;
        public String dataScope = "";
        public boolean deptCheckStrictly;
        public boolean flag;
        public boolean menuCheckStrictly;
        public Object params;
        public long roleId;
        public String roleKey = "";
        public String roleName = "";
        public String roleSort = "";
        public String status = "";

    }
}
