package benchmark_grpc

import (
	
	
	
)

type Op int

const (
	Op1 Op = iota + 1
	Op2
	Op3
)

type Value int

const (
	Value1 Value = iota + 1
	Value2
	Value3
)

type Worker struct {
	ErrCount     int
	SuccessCount int
	value        Value
	evListener   func()
}

func ( *Worker) () {
	.CallOp(Op(rand.Intn(3) + 1))
}

func ( *Worker) ( func()) {
	l("worker", "Subscribe")
	.evListener = 
}

func ( *Worker) () Value {
	return .value
}

func ( *Worker) ( Op) {
	l("worker", "Call op: %v", )

	// assert the value
	if .value != 0 {
		switch  {
		case Op1:
			if .value != Value1 {
				.ErrCount++
			}
			.SuccessCount++
		case Op2:
			if .value != Value2 {
				.ErrCount++
			}
			.SuccessCount++
		case Op3:
			if .value != Value3 {
				.ErrCount++
			}
			.SuccessCount++
		default:
			// err
			.ErrCount++
		}
	}

	// create a rand value
	.value = Value(rand.Intn(3) + 1)

	// call an event
	.notify()
}

func ( *Worker) () {
	l("worker", "Notify")
	.evListener()
}

func l(,  string,  ...any) {
	if os.Getenv("BENCH_DEBUG") == "" {
		return
	}
	log.Printf(+": "+, ...)
}