// Package job defines the job meta data
package job

import "overlord/pkg/types"

// OpType is the operation of job name
type OpType = string

// define Optration types
const (
	// create means create empty cluster into metadata and scale nodes into given.
	OpCreate OpType = "create"

	// OpDestroy means that destroy the whole cluster.
	OpDestroy OpType = "destroy"

	// scale may be scale with given node count
	OpScale OpType = "scale"

	// OpStretch will scale the instance memory and may migrating slot.
	OpStretch OpType = "stretch"

	// OpMigrate means delete specified node and restart in new agent.
	OpMigrate OpType = "migrate"

	// OpFix will trying to run `rustkit fix` to the given cluster(redis cluster only)
	OpFix OpType = "fix"

	// Balance will balance the given cluster
	OpBalance OpType = "balance"

	// OpRestart will trying to restart the special node
	OpRestart OpType = "restart"
)

// Job is a single POD type which represent a single job.
type Job struct {
	// Order was generated by etcd post
	ID   string
	Name string

	CacheType types.CacheType
	Version   string  // service version
	Image     string  // service image
	Num       int     // num of instances ,if redis-cluster,mean master number.
	MaxMem    float64 // max memory MB use of instance.
	CPU       float64 // cpu count for each instance.

	// Scheduler is the name of scheduler and path of etcd
	Scheduler string

	OpType OpType

	Group string

	Nodes []string
	// Users to apply that
	// the first is the job commiter
	Users []string

	// cluster must never be absent unless create.
	Cluster string

	// Params is the given parameters by the frontend interface.
	Params map[string]string

	// ParamsValid is the function which check need to check the jobs.
	ParamsValid func(*Job, map[string]string) (bool, map[string]string) `json:"-"`

	// Args is the auto gennerated arguments for the whole job
	// maybe:
	//     role map
	//     nodes
	//     template data
	//     and so on.
	Args map[string]interface{}

	// ArgsValid is the function which check need to check the jobs.
	ArgsValid func(*Job, map[string]interface{}) (bool, map[string]string) `json:"-"`
}
