package com.qmth.teachcloud.common.bean.result;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.teachcloud.common.entity.BasicSchool;
import com.qmth.teachcloud.common.entity.SysOrg;
import com.qmth.teachcloud.common.entity.SysUser;
import com.qmth.teachcloud.common.enums.AppSourceEnum;
import com.qmth.teachcloud.common.util.ServletUtil;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Description: 登录返回result
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/3/25
 */
public class LoginResult implements Serializable {

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "主键")
    Long id;

    @ApiModelProperty(value = "登录名")
    String loginName;

    @ApiModelProperty(value = "姓名")
    String realName;

    @ApiModelProperty(value = "会话id")
    String sessionId;

    @ApiModelProperty(value = "访问令牌")
    String accessToken;

    @ApiModelProperty(value = "学校信息")
    SchoolNativeBean schoolInfo;

    @ApiModelProperty(value = "机构信息")
    OrgNativeBean orgInfo;

    @ApiModelProperty(name = "角色集合")
    private Set<String> roleList;

    @ApiModelProperty(name = "服务器时间戳")
    private long time;

    @ApiModelProperty(value = "应用来源")
    AppSourceEnum appSource;

    @ApiModelProperty(value = "密码修改次数")
    Integer pwdCount;

    @ApiModelProperty(value = "用户登录验证拦截信息")
    private UserLoginCheckResult userLoginCheckResult;

    @ApiModelProperty(name = "角色来源")
    List<RoleResult> roleSource;

    @ApiModelProperty(name = "返回url")
    String returnUrl;

    public String getReturnUrl() {
        return returnUrl;
    }

    public void setReturnUrl(String returnUrl) {
        this.returnUrl = returnUrl;
    }

    public LoginResult() {

    }

    public LoginResult(SysUser sysUser, String sessionId, String accessToken, Set<String> roleList, AppSourceEnum appSource, List<RoleResult> roleSource) {
        this.id = sysUser.getId();
        ServletUtil.setRequestId(Arrays.asList(id));
        this.loginName = sysUser.getLoginName();
        this.realName = sysUser.getRealName();
        this.sessionId = sessionId;
        this.accessToken = accessToken;
        this.roleList = roleList;
        this.appSource = appSource;
        this.pwdCount = sysUser.getPwdCount();
        this.roleSource = roleSource;
    }

    public LoginResult(SysUser sysUser, String sessionId, String accessToken, SchoolNativeBean schoolInfo, OrgNativeBean orgInfo, AppSourceEnum appSource) {
        this.loginName = sysUser.getLoginName();
        this.realName = sysUser.getRealName();
        this.sessionId = sessionId;
        this.accessToken = accessToken;
        this.schoolInfo = schoolInfo;
        this.orgInfo = orgInfo;
        this.appSource = appSource;
    }

    public List<RoleResult> getRoleSource() {
        return roleSource;
    }

    public void setRoleSource(List<RoleResult> roleSource) {
        this.roleSource = roleSource;
    }

    public AppSourceEnum getAppSource() {
        return appSource;
    }

    public void setAppSource(AppSourceEnum appSource) {
        this.appSource = appSource;
    }

    public Set<String> getRoleList() {
        return roleList;
    }

    public void setRoleList(Set<String> roleList) {
        this.roleList = roleList;
    }

    public OrgNativeBean getOrgInfo() {
        return orgInfo;
    }

    public void setOrgInfo(OrgNativeBean orgInfo) {
        this.orgInfo = orgInfo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public SchoolNativeBean getSchoolInfo() {
        return schoolInfo;
    }

    public void setSchoolInfo(SchoolNativeBean schoolInfo) {
        this.schoolInfo = schoolInfo;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public Integer getPwdCount() {
        return pwdCount;
    }

    public void setPwdCount(Integer pwdCount) {
        this.pwdCount = pwdCount;
    }

    public UserLoginCheckResult getUserLoginCheckResult() {
        return userLoginCheckResult;
    }

    public void setUserLoginCheckResult(UserLoginCheckResult userLoginCheckResult) {
        this.userLoginCheckResult = userLoginCheckResult;
    }

    public class SchoolNativeBean implements Serializable {

        @ApiModelProperty(value = "id")
        @JsonSerialize(using = ToStringSerializer.class)
        Long id;

        @ApiModelProperty(value = "代码")
        String code;

        @ApiModelProperty(value = "名称")
        String name;

        public SchoolNativeBean() {

        }

        public SchoolNativeBean(BasicSchool tbSchool) {
            this.id = tbSchool.getId();
            this.code = tbSchool.getCode();
            this.name = tbSchool.getName();
            schoolInfo = this;
        }

        public SchoolNativeBean(Long id, String code, String name) {
            this.id = id;
            this.code = code;
            this.name = name;
            schoolInfo = this;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public class OrgNativeBean implements Serializable {

        @ApiModelProperty(value = "id")
        @JsonSerialize(using = ToStringSerializer.class)
        Long id;

        @ApiModelProperty(value = "代码")
        String code;

        @ApiModelProperty(value = "名称")
        String name;

        public OrgNativeBean() {

        }

        public OrgNativeBean(SysOrg org) {
            this.id = org.getId();
            this.code = org.getCode();
            this.name = org.getName();
            orgInfo = this;
        }

        public OrgNativeBean(Long id, String code, String name) {
            this.id = id;
            this.code = code;
            this.name = name;
            orgInfo = this;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
