package action

import (
	"context"
	"log"

	"go.temporal.io/sdk/activity"
)

// activityLogger provides logging that works both in and outside Temporal context
type activityLogger struct {
	ctx context.Context
}

func newActivityLogger(ctx context.Context) *activityLogger {
	return &activityLogger{ctx: ctx}
}

func (l *activityLogger) Info(msg string, args ...interface{}) {
	if activity.IsActivity(l.ctx) {
		activity.GetLogger(l.ctx).Info(msg, args...)
	} else {
		log.Printf("INFO: "+msg+" %v", args)
	}
}

func (l *activityLogger) Warn(msg string, args ...interface{}) {
	if activity.IsActivity(l.ctx) {
		activity.GetLogger(l.ctx).Warn(msg, args...)
	} else {
		log.Printf("WARN: "+msg+" %v", args)
	}
}

func (l *activityLogger) Error(msg string, args ...interface{}) {
	if activity.IsActivity(l.ctx) {
		activity.GetLogger(l.ctx).Error(msg, args...)
	} else {
		log.Printf("ERROR: "+msg+" %v", args)
	}
}

func (l *activityLogger) Debug(msg string, args ...interface{}) {
	if activity.IsActivity(l.ctx) {
		activity.GetLogger(l.ctx).Debug(msg, args...)
	} else {
		log.Printf("DEBUG: "+msg+" %v", args)
	}
}
