package com.qmth.sop.business.bean.result;

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

import java.io.Serializable;
import java.util.Arrays;
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 = "机构信息")
    OrgNativeBean orgInfo;

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

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

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

    @ApiModelProperty(name = "版本号")
    String version;

    @ApiModelProperty(value = "人员档案编号(认证编号)")
    private String userArchivesCode;

    @ApiModelProperty(value = "电话号码")
    private String mobileNumber;

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public LoginResult() {

    }

    public LoginResult(SysUser sysUser, String sessionId, String accessToken, Set<String> roleList, AppSourceEnum appSource, String version) {
        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.version = version;
        this.time = System.currentTimeMillis();
    }

    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 long getTime() {
        return time;
    }

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

    public String getUserArchivesCode() {
        return userArchivesCode;
    }

    public void setUserArchivesCode(String userArchivesCode) {
        this.userArchivesCode = userArchivesCode;
    }

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    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;
        }
    }
}
