package topsql

import (
	"time"

	"github.com/pingcap/errors"
)

type ClusterHeader struct {
	Env        *string `header:"x-env"`
	TenantID   *uint64 `header:"x-org-id"`
	ClusterID  *uint64 `header:"x-cluster-id"`
	DeployType string  `header:"x-deploy-type"`
	BizType    string  `header:"x-biz-type"`
}

func (h *ClusterHeader) Validate() error {
	if h.TenantID == nil {
		return errors.New("org id not found")
	}
	if h.ClusterID == nil {
		return errors.New("cluster id not found")
	}
	return nil
}

type InstanceQuery struct {
	StartSecs *float64 `form:"start"`
	EndSecs   *float64 `form:"end"`
}

func (q *InstanceQuery) Validate() error {
	if q.StartSecs == nil {
		return errors.New("start not found")
	}
	if q.EndSecs == nil {
		return errors.New("end not found")
	}
	return nil
}

type SummaryQuery struct {
	StartSecs    *float64       `form:"start"`
	EndSecs      *float64       `form:"end"`
	Window       *time.Duration `form:"window"`
	Top          *int           `form:"top"`
	Instance     *string        `form:"instance"`
	InstanceType *string        `form:"instance_type"`
}

func (q *SummaryQuery) Validate() error {
	if q.StartSecs == nil {
		return errors.New("start not found")
	}
	if q.EndSecs == nil {
		return errors.New("end not found")
	}
	if q.Window == nil {
		return errors.New("window not found")
	}
	if q.Top == nil {
		return errors.New("top not found")
	}
	if q.Instance == nil {
		return errors.New("instance not found")
	}
	if q.InstanceType == nil {
		return errors.New("instance_type not found")
	}
	return nil
}
