package logger

import (
	"os"
	"sync"
)

type HumanLogger struct {
	file *os.File
	mu   sync.Mutex
}

func NewHumanLogger() (*HumanLogger, error) {
	path, err := GetGPIOLogPath()
	if err != nil {
		return nil, err
	}

	f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
	if err != nil {
		return nil, err
	}

	return &HumanLogger{file: f}, nil
}

func (l *HumanLogger) Write(data string) {
	l.mu.Lock()
	defer l.mu.Unlock()

	l.file.WriteString(data)
	l.file.Sync()
}

func (l *HumanLogger) Close() error {
	return l.file.Close()
}