#ifndef NET_H
#define NET_H

#include <winsock2.h>
#include <stdint.h>

#define MAX_CLIENTS 64
#define BUFFER_SIZE 1024

typedef enum {
    PACKET_PING = 1,
    PACKET_TEXT,
    PACKET_CLIENT_JOINED,
    PACKET_CLIENT_LEFT,
    PACKET_PLAYER_MOVE,
    PACKET_PLAYER_STATE,
    PACKET_MAX
} PacketType;

typedef struct {
    uint8_t type;
    uint16_t size;
    char data[];
} Packet;

Packet* create_packet(PacketType type, const void* data, uint16_t size);
int serialize_packet(Packet* pkt, char* buffer);
Packet* deserialize_packet(const char* buffer, int len);
void destroy_packet(Packet* pkt);

// Networking setup
void net_init();
void net_cleanup();
SOCKET net_connect(const char* ip, int port);
SOCKET net_bind_and_listen(int port);
SOCKET net_accept(SOCKET server);
void set_socket_nonblocking(SOCKET sock, int enable);


#endif
