package com.ruoyi.jarvis.domain.dto;

import java.io.Serializable;

/**
 * WPS365 Token信息
 * 
 * @author system
 */
public class WPS365TokenInfo implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /** 访问令牌 */
    private String accessToken;
    
    /** 刷新令牌 */
    private String refreshToken;
    
    /** 令牌类型 */
    private String tokenType;
    
    /** 过期时间（秒） */
    private Integer expiresIn;
    
    /** 作用域 */
    private String scope;
    
    /** 用户ID */
    private String userId;
    
    /** 创建时间戳（毫秒） */
    private Long createTime;

    public WPS365TokenInfo() {
        this.createTime = System.currentTimeMillis();
    }

    public String getAccessToken() {
        return accessToken;
    }

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

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public Integer getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Integer expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
    
    /**
     * 检查token是否过期
     */
    public boolean isExpired() {
        if (expiresIn == null || createTime == null) {
            return true;
        }
        long currentTime = System.currentTimeMillis();
        long expireTime = createTime + (expiresIn * 1000L);
        // 提前5分钟认为过期，留出刷新时间
        return currentTime >= (expireTime - 5 * 60 * 1000);
    }
}

