package v2

import (
	"testing"
	"time"

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

func TestDeletionPlan_IsEmpty(t *testing.T) {
	tests := []struct {
		name     string
		plan     *DeletionPlan
		expected bool
	}{
		{
			name: "empty plan with no resources",
			plan: &DeletionPlan{
				ConfigName:        "test-config",
				AppToDelete:       nil,
				InstancesToDelete: []InstanceDeletion{},
			},
			expected: true,
		},
		{
			name: "plan with app deletion",
			plan: &DeletionPlan{
				ConfigName: "test-config",
				AppToDelete: &AppDeletion{
					Name:         "test-app",
					Organization: "test-org",
					Version:      "1.0",
					Region:       "US",
				},
				InstancesToDelete: []InstanceDeletion{},
			},
			expected: false,
		},
		{
			name: "plan with instance deletion",
			plan: &DeletionPlan{
				ConfigName:  "test-config",
				AppToDelete: nil,
				InstancesToDelete: []InstanceDeletion{
					{
						Name:         "test-instance",
						Organization: "test-org",
					},
				},
			},
			expected: false,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := tt.plan.IsEmpty()
			assert.Equal(t, tt.expected, result)
		})
	}
}

func TestDeletionPlan_GenerateSummary(t *testing.T) {
	plan := &DeletionPlan{
		ConfigName: "test-config",
		AppToDelete: &AppDeletion{
			Name:         "test-app",
			Organization: "test-org",
			Version:      "1.0",
			Region:       "US",
		},
		InstancesToDelete: []InstanceDeletion{
			{
				Name:         "test-instance-1",
				Organization: "test-org",
				CloudletName: "cloudlet-1",
				CloudletOrg:  "cloudlet-org",
			},
			{
				Name:         "test-instance-2",
				Organization: "test-org",
				CloudletName: "cloudlet-2",
				CloudletOrg:  "cloudlet-org",
			},
		},
		TotalActions:      3,
		EstimatedDuration: 30 * time.Second,
	}

	summary := plan.GenerateSummary()

	assert.Contains(t, summary, "test-config")
	assert.Contains(t, summary, "DELETE application 'test-app'")
	assert.Contains(t, summary, "DELETE 2 instance(s)")
}
