//go:generate ${GOBIN}/dummygen -d=api_dummy.go -package=api ${GO_MODULE}/pkg/service/k8supgrade/task/api API
//go:generate ${GOBIN}/mockgen -destination api_mock.go -package=api ${GO_MODULE}/pkg/service/k8supgrade/task/api API
package api

import (
	"context"

	entity "github.com/tidbcloud/devops/entity/k8supgrade"
)

type SortByType string
type OrderType string

type ListTasksParam struct {
	CloudProviders []string
	EOSVersions    []string
	Status         []entity.TaskStatus

	SortBy  SortByType
	Order   OrderType
	Page    int // default 1
	PerPage int // default 20
}

type CreateTaskParam struct {
	Name            string
	CloudProvider   string
	EOSVersion      string
	MaxRestartTimes uint32
	Deadline        int64
	Applicant       string

	// Selectors:
	SelectorType  string
	SelectorValue string
}

type GetTaskParam struct {
	TaskID                  uint64
	WithExcludedK8sClusters bool
}

type CloseTaskParam struct {
}

type UpdateTaskParam struct {
	TaskToUpdate *entity.Task
}

type UpdateK8sClusterParam struct {
	Cluster *entity.K8sCluster
}

type GetK8sClusterParam struct {
	TaskID  uint64
	K8sName string
}

type API interface {
	CreateTask(context.Context, CreateTaskParam) (uint64, error)
	ListTasks(context.Context, ListTasksParam) ([]*entity.Task, int64, error)
	GetTask(context.Context, GetTaskParam) (*entity.Task, error)
	ListSupportedEOSVersions(context.Context) (map[string][]string, error)
	CloseTask(context.Context, uint64) error
	UpdateTask(context.Context, uint64, UpdateTaskParam) error
	SubmitTask(context.Context, uint64) error
	DeleteTask(context.Context, uint64) error

	GetK8sCluster(context.Context, GetK8sClusterParam) (*entity.K8sCluster, error)
	UpdateK8sCluster(context.Context, uint64, string, UpdateK8sClusterParam) error
	UpdateK8sClusterAutoGeneration(context.Context, uint64, string, bool) error
	ExcludeK8sCluster(context.Context, uint64, string) error
	CancelUpgradeK8sCluster(context.Context, uint64, string) error

	NotifyTask(context.Context, entity.NotifyParam) error
	GetTaskNotice(context.Context, uint64, string) (string, error)
	UpsertTaskNotice(context.Context, uint64, string, string, string) error

	IsK8sUpgradeAdmin(context.Context, string) bool
}
