package marketing

import (
	"testing"

	"github.com/pingcap/dbaas/billing2/db/entity"
)

// TestIsPartnerManagedCustomer_TableDriven exhaustively covers the
// supported billing-config types. If a new partner-managed customer
// type comes online, the test must be updated alongside the new
// case in the helper, and getResellerTenantAndBillingConfig must
// grow a matching case.
//
// Lives in the marketing package (not tests) so it can call the
// unexported isPartnerManagedCustomer directly.
func TestIsPartnerManagedCustomer_TableDriven(t *testing.T) {
	cases := []struct {
		name string
		t    string
		want bool
	}{
		// partner-managed — must classify true
		{"marketplace reseller managed customer", entity.BillingConfigType_MarketplaceResellerManagedCustomer, true},
		{"resale customer", entity.BillingConfigType_ResaleCustomer, true},

		// everything else — must classify false
		{"plain direct customer", entity.BillingConfigType_DirectCustomer, false},
		{"msp customer (not partner — partner binds on customer's behalf)", entity.BillingConfigType_MSPCustomer, false},
		{"msp partner (self)", entity.BillingConfigType_MSP, false},
		{"resale partner (self)", entity.BillingConfigType_ResalePartner, false},
		{"aws cppo reseller (self)", entity.BillingConfigType_AWSCPPOReseller, false},
		{"aws cppo customer (separate enum)", entity.BillingConfigType_AWSCPPOCustomer, false},
		{"marketplace reseller (self)", entity.BillingConfigType_MarketplaceReseller, false},
		{"alicloud (out of scope)", entity.BillingConfigType_Alicloud, false},
		{"empty string", "", false},
	}
	for _, tc := range cases {
		tc := tc
		t.Run(tc.name, func(t *testing.T) {
			if got := isPartnerManagedCustomer(tc.t); got != tc.want {
				t.Errorf("isPartnerManagedCustomer(%q) = %v, want %v", tc.t, got, tc.want)
			}
		})
	}
}
