// Package task provides unified task type definitions and interfaces package task import ( "context" "fmt" "github.com/gofrs/uuid" "gorm.io/gorm" ) // TaskParams defines the interface for task-specific parameters type TaskParams interface { Validate() error GetType() UnifiedTaskType ToMap() map[string]interface{} FromMap(params map[string]interface{}) error } // BaseTask provides common functionality for all task implementations type BaseTask struct { taskType UnifiedTaskType params TaskParams name string } // NewBaseTask creates a new BaseTask instance func NewBaseTask(taskType UnifiedTaskType, params TaskParams, name string) *BaseTask { return &BaseTask{ taskType: taskType, params: params, name: name, } } func (t *BaseTask) GetType() UnifiedTaskType { return t.taskType } func (t *BaseTask) GetParams() TaskParams { return t.params } func (t *BaseTask) GetName() string { return t.name } func (t *BaseTask) Validate() error { if t.params == nil { return fmt.Errorf("task parameters cannot be nil") } if t.taskType != t.params.GetType() { return fmt.Errorf("task type mismatch: expected %s, got %s", t.taskType, t.params.GetType()) } return t.params.Validate() } // Execute is a placeholder; concrete task types override this via embedding. func (t *BaseTask) Execute(_ context.Context, _ uuid.UUID, _ *gorm.DB) error { return fmt.Errorf("Execute not implemented for task type %s", t.taskType) }