package example

import (
	"errors"
	"log/slog"
	"time"

	"quantex.com/qfixdpl/src/app"
	googlechat "quantex.com/qfixdpl/src/client/notify/google"
	"quantex.com/qfixdpl/src/client/res"
	"quantex.com/qfixdpl/src/common/logger"
	"quantex.com/qfixdpl/src/common/tracerr"
)

func TracerrRunner(cfg app.Config) error {
	slog.Info("Hello Tracerr")

	notify := googlechat.New(cfg.Notify.Google)
	logger.SetNotifier(notify)

	readFile()

	errOrg := errors.New("--eror-- orig")
	err := tracerr.Errorf("eror: %w", errOrg)

	slog.Info("Is the error??")
	if errors.Is(err, errOrg) {
		slog.Info("Yes, it's the error!")
	}

	time.Sleep(2 * time.Second)

	return nil
}

func readFile() {
	f, err := res.ReadFile("res/file.txt")
	if err != nil {
		panic(err)
	}

	slog.Info(">>> " + string(f))
}
