package comms

import (
	"encoding/gob"
	"log"
	"net"
	"time"
)

type TCPChannel struct {
	// can be any connection, including the ssh connnection before it is
	// passed on to SSH during initialization of converge to agent communication
	Peer    net.Conn
	Encoder *gob.Encoder
	Decoder *gob.Decoder
}

// Synchronous functions with timeouts and error handling.
func (channel TCPChannel) SendAsync(object any, timeout time.Duration) error {
	return nil
}

func (channel TCPChannel) ReceiveAsync(object any, timeout time.Duration) error {
	return nil
}

func (channel TCPChannel) Send(object any) error {
	err := channel.Encoder.Encode(ConvergeMessage{Value: object})
	if err != nil {
		log.Printf("Encoding error %v", err)
	}
	return err
}