// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
	"regexp"
	"testing"

	"github.com/hashicorp/terraform-plugin-testing/helper/resource"
	"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

func TestComputeTaxFunction_Known(t *testing.T) {
	// Should only be used for resource that don't have any external dependencies.
	resource.UnitTest(t, resource.TestCase{
		TerraformVersionChecks: []tfversion.TerraformVersionCheck{
			tfversion.SkipBelow(tfversion.Version1_8_0), // Functions were introduced in 1.8.0
		},
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			{
				Config: `output "test" {
          value = provider::hashicups::compute_tax(5.00, 0.085)
        }`,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckOutput("test", "5.43")), // 5*1.085 == 5.425
			},
		},
	})
}

func TestComputeTaxFunction_Null(t *testing.T) {
	resource.UnitTest(t, resource.TestCase{
		TerraformVersionChecks: []tfversion.TerraformVersionCheck{
			tfversion.SkipBelow(tfversion.Version1_8_0),
		},
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			{
				Config: `output "test" {
          value = provider::hashicups::compute_tax(null, 0.085)
        }`,
				ExpectError: regexp.MustCompile(`argument must not be null`),
			},
		},
	})
}