package context

import (
	"fmt"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec-experiment/client_golang/model"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/log"
	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/recconf"
	"strings"
)

type IParam interface {
	GetParameter(name string) interface{}
}
type RecommendContext struct {
	Debug            bool
	Size             int
	Param            IParam
	Config           *recconf.RecommendConfig
	ExperimentResult *model.ExperimentResult
	RecommendId      string
	ExpId            string
	Log              []string
}

func NewRecommendContext() *RecommendContext {
	context := RecommendContext{Size: -1, Debug: false, Log: make([]string, 0, 16)}
	return &context
}
func (r *RecommendContext) GetParameter(name string) interface{} {
	return r.Param.GetParameter(name)
}

func (r *RecommendContext) LogDebug(msg string) {
	if r.Debug {
		r.Log = append(r.Log, fmt.Sprintf("[DEBUG] %s", strings.Replace(msg, "\t", "  ", -1)))
	}
}
func (r *RecommendContext) LogInfo(msg string) {
	r.Log = append(r.Log, fmt.Sprintf("[INFO] %s", strings.Replace(msg, "\t", "  ", -1)))
	log.Info(fmt.Sprintf("req=%s\t%s", r.RecommendId, msg))
}
func (r *RecommendContext) LogWarning(msg string) {
	r.Log = append(r.Log, fmt.Sprintf("[WARN] %s", strings.Replace(msg, "\t", "  ", -1)))
	log.Warning(fmt.Sprintf("req=%s\t%s", r.RecommendId, msg))
}
func (r *RecommendContext) LogError(msg string) {
	r.Log = append(r.Log, fmt.Sprintf("[ERROR] %s", strings.Replace(msg, "\t", "  ", -1)))
	log.Error(fmt.Sprintf("req=%s\t%s", r.RecommendId, msg))
}
