import { Server as HttpServer } from 'http';
import { ServerOptions, Server as SocketIoServer, Namespace, Socket } from 'socket.io';

export class SocketServer {
    private io: SocketIoServer;

    constructor(server: HttpServer, options?: Partial<ServerOptions>) {
        this.io = new SocketIoServer(server, options);
    }

    use(name: string | ((socket: Socket) => void), fn?: (socket: Socket) => void): boolean {
        if (!name) return false;
        if (typeof name === 'string') {
            if (!fn) return false;
            if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');

            this.io.of(name).on('connection', fn);
        } else if (typeof name === 'function') {
            this.io.on('connection', name);
        }
        return true;
    }
} 