package composition

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestCreateChild(t *testing.T) {
	composer := NewWorkflowComposer()
	config := map[string]interface{}{"tasks": 5}
	
	child, err := composer.CreateChild("T0.1", config)
	assert.NoError(t, err)
	assert.NotNil(t, child)
	assert.Equal(t, "T0.1", child.ParentTask)
}

func TestGetChild(t *testing.T) {
	composer := NewWorkflowComposer()
	
	child, _ := composer.CreateChild("T0.1", map[string]interface{}{})
	
	retrieved, found := composer.GetChild(child.ID)
	assert.True(t, found)
	assert.Equal(t, child.ID, retrieved.ID)
}

func TestListChildren(t *testing.T) {
	composer := NewWorkflowComposer()
	
	for i := 0; i < 3; i++ {
		composer.CreateChild("T0.1", map[string]interface{}{})
	}
	
	children := composer.ListChildren()
	assert.Equal(t, 3, len(children))
}

func TestSetChildStatus(t *testing.T) {
	composer := NewWorkflowComposer()
	
	child, _ := composer.CreateChild("T0.1", map[string]interface{}{})
	
	err := composer.SetChildStatus(child.ID, "completed")
	assert.NoError(t, err)
	
	updated, _ := composer.GetChild(child.ID)
	assert.Equal(t, "completed", updated.Status)
}
