import { MessageBody, OnGatewayConnection, OnGatewayDisconnect, SubscribeMessage, WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
import { Server, Socket } from "socket.io";

@WebSocketGateway({
    cors: true
})

export class AppGetaway implements OnGatewayDisconnect, OnGatewayConnection {
    @WebSocketServer() server: Server

    handleDisconnect(client: Socket) {
        console.log(`${client.id} disconnected`)
    }

    handleConnection(client: Socket, ...args: any[]) {
        console.log(`${client.id} connected`)
    }

    onAddCandidate(registrationData: any) {
        this.server.emit('candidateRegistered', registrationData);
    }

    onUpdateCandidate(updatedData: any) {
        this.server.emit('candidateUpdated', updatedData);
    }

    onDeleteCandidate(deletedId: number) {
        this.server.emit('candidateDeleted', deletedId);
    }
}