package vo

import (
	"time"

	"github.com/tidbcloud/chaos-svc/pkg/domain/constant"
)

type WorkflowNode struct {
	ID          uint64
	Name        string
	CreatedAt   time.Time
	Status      constant.WorkflowNodeStatus
	Message     string
	CompletedAt *time.Time
}

func (w *WorkflowNode) IsRunning() bool {
	return w.Status == constant.WorkflowNodeStatusRunning
}

func (w *WorkflowNode) IsSuccess() bool {
	return w.Status == constant.WorkflowNodeStatusSuccess
}

func (w *WorkflowNode) IsFailed() bool {
	return w.Status == constant.WorkflowNodeStatusFailed
}

func (w *WorkflowNode) SetStatusSuccess(now time.Time) {
	w.Status = constant.WorkflowNodeStatusSuccess
	w.CompletedAt = &now
}

func (w *WorkflowNode) SetStatusFailed(now time.Time, message string) {
	w.Status = constant.WorkflowNodeStatusFailed
	w.Message = message
	w.CompletedAt = &now
}
