package flattens

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-log/tflog"
)

// FlattenSimpleTypeToList convert a slice of simple type to a types.List
func FlattenSimpleTypeToList(ctx context.Context, elementType attr.Type, elements any) types.List {
	res, diags := types.ListValueFrom(ctx, elementType, elements)
	if diags != nil {
		tflog.Error(ctx, fmt.Sprint("Error FlattenSimpleTypeToList", diags))
	}
	return res
}

// FlattenSimpleTypeToSet convert a slice of simple type to a types.Set
func FlattenSimpleTypeToSet(ctx context.Context, elementType attr.Type, elements any) types.Set {
	res, diags := types.SetValueFrom(ctx, elementType, elements)
	if diags != nil {
		tflog.Error(ctx, fmt.Sprint("Error FlattenSimpleTypeToSet", diags))
	}
	return res
}
