package entity

import (
	"testing"

	apiv1 "github.com/tidbcloud/cluster-service-ng/api/cluster-service-ng/v1beta"
	"github.com/tidbcloud/cluster-service-ng/pkg/storage/mysql/schema"
)

func TestLightweightRestore_GetLastAction(t *testing.T) {
	tests := []struct {
		name            string
		executedActions string
		expected        string
	}{
		{
			name:            "empty executed actions",
			executedActions: "",
			expected:        "",
		},
		{
			name:            "single action",
			executedActions: "action1",
			expected:        "action1",
		},
		{
			name:            "multiple actions",
			executedActions: "action1,action2,action3",
			expected:        "action3",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			r := &LightweightRestore{
				LightweightRestore: schema.LightweightRestore{
					ExecutedActions: tt.executedActions,
				},
			}

			result := r.GetLastAction()

			if result != tt.expected {
				t.Errorf("GetLastAction() = %q, expected %q", result, tt.expected)
			}
		})
	}
}

// Make sure the Storage type alias is correct by using apiv1.Component_Storage
var _ *Storage = (*apiv1.Component_Storage)(nil)
