package com.ruoyi.jarvis.domain.dto;

import java.io.Serializable;

/**
 * 金山文档 OAuth 令牌（存 Redis）
 */
public class KdocsTokenInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    private String accessToken;
    private String refreshToken;
    private String tokenType;
    private Integer expiresIn;
    private String scope;
    /** 本系统用于关联 Redis 的用户标识，通常取金山 open_id */
    private String userId;
    private Long createTime;

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

    public boolean isExpired() {
        if (accessToken == null || accessToken.isEmpty()) {
            return true;
        }
        // 部分 OAuth 响应不返回 expires_in；若按 null 判过期会导致前端误判「未授权」
        if (expiresIn == null || createTime == null) {
            return false;
        }
        long expireTime = createTime + (expiresIn * 1000L);
        return System.currentTimeMillis() >= (expireTime - 5 * 60 * 1000L);
    }

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