package steps

import (
	"context"
	"fmt"

	"github.com/pingcap/test-infra/caselib/pkg/utils"
)

type extractValue struct {
	input  *string
	begin  string
	end    string
	output *string
}

func (c extractValue) String() string {
	return fmt.Sprintf("Assert Value, input: %s, extract_begin_str: %s, extract_end_str: %s, output: %s", *c.input, c.begin, c.end, *c.output)
}

func (c extractValue) Execute(ctx context.Context) error {
	*c.output = utils.ExtractValues(*c.input, c.begin, c.end)
	return nil
}

var _ Step = &extractValue{}

func ExtractValue(input *string, begin, end string, output *string) *extractValue {
	return &extractValue{
		input,
		begin,
		end,
		output,
	}
}

func (b *Builder) ExtractValue(input *string, begin, end string, output *string) *Builder {
	b.steps = append(b.steps, ExtractValue(input, begin, end, output))
	return b
}
