package com.xindazhou.user.service.oauth2;

import com.xindazhou.user.dal.dataobject.oauth2.OAuth2ClientDO;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;

/**
 * OAuth2.0 Client Service 实现类（简化版）
 * 
 * 使用默认客户端配置，不进行复杂的客户端验证
 *
 * @author hmy
 */
@Service
public class OAuth2ClientServiceImpl implements OAuth2ClientService {

    /**
     * 默认客户端配置
     * - 访问令牌有效期：30分钟（1800秒）
     * - 刷新令牌有效期：30天（2592000秒）
     */
    private static final int DEFAULT_ACCESS_TOKEN_VALIDITY_SECONDS = 1800;
    private static final int DEFAULT_REFRESH_TOKEN_VALIDITY_SECONDS = 2592000;
    private static final String DEFAULT_CLIENT_ID = "default";

    @Override
    public OAuth2ClientDO validOAuthClientFromCache(String clientId) {
        // 简化处理：只验证 clientId 是否为 "default"
        if (!DEFAULT_CLIENT_ID.equals(clientId)) {
            throw new IllegalArgumentException("不支持的客户端编号：" + clientId);
        }
        
        // 返回默认客户端配置
        OAuth2ClientDO client = new OAuth2ClientDO();
        client.setClientId(DEFAULT_CLIENT_ID);
        client.setAccessTokenValiditySeconds(DEFAULT_ACCESS_TOKEN_VALIDITY_SECONDS);
        client.setRefreshTokenValiditySeconds(DEFAULT_REFRESH_TOKEN_VALIDITY_SECONDS);
        client.setScopes(Arrays.asList("user.read", "user.write"));
        return client;
    }

}

