package server

import (
	"io"
	"time"
)

//IsRunning is exported
func (server *Handler) IsRunning() bool {
	return server.isRunning
}

//ReadAllLog is exported
func (server *Handler) ReadAllLog() []Log {
	return server.log
}

//ReadRangeLog is exported
func (server *Handler) ReadRangeLog(start int, end int) []Log {
	return server.log[start:end]
}

//LenLog is exported
func (server *Handler) LenLog() int {
	return len(server.log)
}

//SendCommand is exported
func (server *Handler) SendCommand(command string) bool {
	if server.isRunning {
		io.WriteString(server.stdin, command+"\n")
		return true
	} else {
		return false
	}
}

//AddLogEntry is exported function
func (server *Handler) AddLogEntry(line string) {
	if string(line) != "" {
		newLog := Log{
			ID:        server.ID,
			Timestamp: time.Now(),
			Log:       string(line),
		}
		server.ID++
		server.log = append(server.log, newLog)
	}
}
