import type { Ref } from 'vue';
import { WsEventManager } from '@/plugins/websocket/core/event-manager';

export enum WsEvent {
  CONNECTED = 'CONNECTED',
  LOCK_CLIENT_SCREEN = 'LOCK_CLIENT_SCREEN'
}

export enum WsSendEventType {
  BIND_CONNECT_ID = 'bind_connect_id',
  LOCK_CLIENT_SCREEN = 'lock_client_screen',
}

export enum WsConnectionStatus {
  CONNECTING = 'connecting',
  CONNECTED = 'connected',
  DISCONNECTED = 'disconnected',
  ERROR = 'error'
}

export enum WsMessageType {
  INCOMING = 'incoming',
  OUTGOING = 'outgoing',
  SYSTEM = 'system'
}

export interface WsMessage {
  content: string;
  type: WsMessageType;
  timestamp: Date;
}

export interface WsConfig {
  url: string;
  protocols?: string;
  reconnectAttempts: number;
  reconnectDelay: number;
  autoConnect?: boolean;
}

export interface WsPluginOptions {
  globalConfig?: Partial<WsConfig>;
}

export interface WsEventListener {
  handler: Function;
  id: string;
}

export interface WsEventContext {
  id: string;
  remove(): void;
}

export interface WsInstance {
  isConnected: Ref<boolean>;
  isConnecting: Ref<boolean>;
  connectionStatus: Ref<WsConnectionStatus>;
  messages: Ref<WsMessage[]>;
  statusClass: Ref<string>;

  connectSocket: () => void;
  disconnectSocket: () => void;
  sendMessage: (event: WsSendEventType, data: any) => void;
  clearMessages: () => void;
  events: WsEventManager; // 重命名为更清晰的events
}
