package diag

import (
	"net/url"

	"github.com/pingcap/test-infra/services/sdkserver/diag/client"
)

// copy from: https://github.com/pingcap/diag/blob/v0.7.0/k8s/server/collectors.go#L39-L48
// diag doesn't define a status type, so I cannot either = =.

// collect job status
const (
	TaskStatusAccepted  = "accepted"
	TaskStatusRunning   = "running"
	TaskStatusError     = "error"
	TaskStatusFinish    = "finished"
	TaskStatusCancel    = "cancelled"
	TaskStatusPurge     = "purged" // data set deleted
	TaskStatusInterrupt = "interrupted"
)

func IsStatusRunning(status string) bool {
	return status == TaskStatusAccepted || status == TaskStatusRunning
}

func IsStatusSuccess(status string) bool {
	return status == TaskStatusFinish
}

func IsStatusError(status string) bool { // treat all other status as error for safety
	return !(IsStatusRunning(status) || IsStatusSuccess(status))
}

// copy from: https://github.com/pingcap/diag/blob/v0.7.0/collector/collect.go#L41-L51

// types of data to collect
const (
	CollectTypeSystem        = "system"
	CollectTypeMonitor       = "monitor"
	CollectTypeLog           = "log"
	CollectTypeConfig        = "config"
	CollectTypeSchema        = "db_vars"
	CollectTypePerf          = "perf"
	CollectTypeAudit         = "audit_log"
	CollectTypeDebug         = "debug"
	CollectTypeComponentMeta = "component_meta"
)

var DefaultClient = client.Default

func InitDefaultClient(diagURL *url.URL) {
	DefaultClient = client.NewHTTPClientWithConfig(nil, client.DefaultTransportConfig().WithHost(diagURL.Host).WithSchemes([]string{diagURL.Scheme}))
}
