package com.dspread.pos.common.websocket;

import android.util.Log;

public class WebSocketConnectionManager {
    private static final String TAG = "WSConnectionManager";
    private static WebSocketConnectionManager instance;
    private static final String DEFAULT_WS_URL = "ws://yuzpayqr.mulberrypos.com:4780";

    private final WebSocketManager webSocketManager;

    public static synchronized WebSocketConnectionManager getInstance() {
        if (instance == null) {
            instance = new WebSocketConnectionManager();
        }
        return instance;
    }

    private WebSocketConnectionManager() {
        webSocketManager = WebSocketManager.getInstance();
    }

    /**
     * Connect using default URL
     */
    public void connect() {
        connect(DEFAULT_WS_URL);
    }

    /**
     * Connect using custom URL
     */
    public void connect(String serverUrl) {
        webSocketManager.connect(serverUrl);
    }

    /**
     * Disconnect from WebSocket
     */
    public void disconnect() {
        webSocketManager.disconnect();
    }

    /**
     * Add listener
     */
    public void addListener(WebSocketManager.WebSocketListener listener) {
        webSocketManager.addListener(listener);
    }

    /**
     * Remove listener
     */
    public void removeListener(WebSocketManager.WebSocketListener listener) {
        webSocketManager.removeListener(listener);
    }

    /**
     * Send message
     */
    public boolean sendMessage(String message) {
        return webSocketManager.sendMessage(message);
    }

    /**
     * Check connection status
     */
    public boolean isConnected() {
        return webSocketManager.isConnected();
    }

    /**
     * Get connection state
     */
    public WebSocketManager.ConnectionState getConnectionState() {
        return webSocketManager.getConnectionState();
    }

    /**
     * Enable/disable auto-reconnection
     */
    public void setReconnectionEnabled(boolean enabled) {
        webSocketManager.setReconnectionEnabled(enabled);
    }

    /**
     * Clean up
     */
    public void shutdown() {
        webSocketManager.shutdown();
    }
}