package crossplane

import (
	"context"

	"github.com/crossplane-contrib/provider-aws/apis/ec2/v1beta1"
	"sigs.k8s.io/controller-runtime/pkg/client"

	"github.com/tidbcloud/infra-provider/pkg/namer"
)

// GetNodeSubnetsByZonesFromCR returns the node subnet IDs for the given zones.
// It does not get the subnet data from AWS, but from the crossplane CR.
func LegacyGetNodeSubnetsByZonesFromCR(ctx context.Context, infraCli client.Client, vpcName string, zones []string) (subnetIDs []string) {
	for _, zone := range zones {
		nodeSubnetCRName := namer.NodesSubnetName(vpcName, zone)
		var subnet v1beta1.Subnet
		if err := infraCli.Get(ctx, client.ObjectKey{Name: nodeSubnetCRName}, &subnet); err == nil {
			subnetIDs = append(subnetIDs, subnet.Status.AtProvider.SubnetID)
		}
	}
	return subnetIDs
}
