package com.cico.nest.lcdp.boot.core.system.dal.dataobject.oauth2;

import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.cico.nest.lcdp.boot.tenant.core.db.TenantBaseDO;
import com.cico.nest.lcdp.framework.common.enums.UserTypeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

/**
 * OAuth2 访问令牌 DO
 *
 * 如下字段，暂时未使用，暂时不支持：
 * user_name、authentication（用户信息）
 *
 * @author zws
 */
@TableName(value = "system_oauth2_access_token", autoResultMap = true)
@KeySequence("system_oauth2_access_token_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
public class OAuth2AccessTokenDO extends TenantBaseDO {

    /**
     * 编号，数据库递增
     */
    @TableId
    private Long id;
    /**
     * 访问令牌
     */
    private String accessToken;
    /**
     * 刷新令牌
     */
    private String refreshToken;
    /**
     * 用户编号
     */
    private Long userId;
    /**
     * 用户类型
     *
     * 枚举 {@link UserTypeEnum}
     */
    private Integer userType;
    /**
     * 客户端编号
     *
     * 关联 {@link OAuth2ClientDO#getId()}
     */
    private String clientId;
    /**
     * 授权范围
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> scopes;
    /**
     * 过期时间
     */
    private LocalDateTime expiresTime;

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

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

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

    public OAuth2AccessTokenDO setUserId(Long userId) {
        this.userId = userId;
        return this;
    }

    public OAuth2AccessTokenDO setUserType(Integer userType) {
        this.userType = userType;
        return this;
    }

    public OAuth2AccessTokenDO setClientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    public OAuth2AccessTokenDO setScopes(List<String> scopes) {
        this.scopes = scopes;
        return this;
    }

    public OAuth2AccessTokenDO setExpiresTime(LocalDateTime expiresTime) {
        this.expiresTime = expiresTime;
        return this;
    }
}
