package workload

import (
	"net/url"
	"strconv"
	"strings"
	"time"
)

// ./bin/go-ycsb load mysql -P ./workloads/oncall2929
// -p mysql.host=127.0.0.1 -p mysql.port=4000 -p operationcount=500000 -p autocommit=1 -p databasename=test123 -p tablename=test123
// --threads=5

const ()

type QihooOption struct {
	// stage can only be `load` or `run`
	Command        CommandType
	PropertyFile   string
	PropertyValues []string
	Threads        int

	Duration time.Duration

	DB string
}

func (o *QihooOption) Parse(dbURL *url.URL) *CMD {
	var (
		cmd    = "/go-ycsb " + o.Command.String() + " mysql "
		params []string
	)

	params = append(params, "-P "+o.PropertyFile)

	o.PropertyValues = append(o.PropertyValues, "mysql.host="+dbURL.Hostname())
	o.PropertyValues = append(o.PropertyValues, "mysql.port="+dbURL.Port())
	for _, item := range o.PropertyValues {
		params = append(params, "-p "+item)
	}
	params = append(params, "--threads="+strconv.Itoa(o.Threads))

	cmd = cmd + strings.Join(params, " ")
	timeout := o.Duration + time.Minute*10
	return NewCMD(cmd, timeout)
}

func (o *QihooOption) SetCommand(command CommandType) {
	o.Command = command
}

func (o *QihooOption) GetTableNames() []string {
	return nil
}
