/**
 * 统一登录SDK入口文件
 * 支持OAuth2授权码模式，提供完整的Token管理和用户信息管理功能
 */

// 导出核心类和功能
export { Auth } from './core/auth';
export { TokenManager } from './core/token';
export { HttpClient, HttpError } from './core/http';
export { Storage } from './utils/storage';
export { RouterGuard, RouterGuardOptions } from './guards/router';

// 导出工具函数
export { 
  generateRandomString, 
  parseQueryParams, 
  buildQueryParams, 
  generateAuthorizationUrl, 
  isCallbackUrl 
} from './utils/url';

// 导出类型定义
export * from './types';

// 导出Vue插件
export { VuePlugin, createVuePlugin } from './plugins/vue';

// 创建默认SDK实例
import { SDKConfig, UnifiedLoginSDK } from './types';
import { Auth as AuthCore } from './core/auth';
import { Storage as StorageCore } from './utils/storage';

/**
 * 默认SDK实例
 */
const defaultStorage = new StorageCore();
const defaultAuth = new AuthCore(defaultStorage);

/**
 * 默认导出的SDK实例
 */
export const unifiedLoginSDK: UnifiedLoginSDK = {
  init: (config: SDKConfig) => {
    defaultAuth.init(config);
  },
  getToken: () => {
    return defaultAuth.getToken()
  },
  login: (redirectUri?: string) => {
    return defaultAuth.login(redirectUri);
  },
  logout: () => {
    return defaultAuth.logout();
  },
  handleCallback: () => {
    return defaultAuth.handleCallback();
  },
  getRoutes: () => {
    return defaultAuth.getRoutes();
  },
  getUserInfo: () => {
    return defaultAuth.getUserInfo();
  },
  isAuthenticated: () => {
    return defaultAuth.isAuthenticated();
  },
  hasRole: (role: string | string[]) => {
    return defaultAuth.hasRole(role);
  },
  hasAllRoles: (roles: string[]) => {
    return defaultAuth.hasAllRoles(roles);
  },
  hasPermission: (permission: string | string[]) => {
    return defaultAuth.hasPermission(permission);
  },
  hasAllPermissions: (permissions: string[]) => {
    return defaultAuth.hasAllPermissions(permissions);
  },
  on: (event, callback) => {
    return defaultAuth.on(event, callback);
  },
  off: (event, callback) => {
    return defaultAuth.off(event, callback);
  },
  isCallback: () => {
    return defaultAuth.isCallback();
  }
};

// 默认导出
export default unifiedLoginSDK;

// 版本信息
export const version = '1.0.0';
