package paymenthandler

import (
	"testing"

	"github.com/pingcap/dbaas/billing2/config"
	"github.com/pingcap/dbaas/billing2/forms"
	"github.com/pingcap/dbaas/billing2/handler/gcphandler/auth"
	"github.com/shopspring/decimal"
	"github.com/spf13/viper"
	"github.com/stretchr/testify/assert"
)

const (
	GCPProject        = ""
	GCPPubSubTopic    = ""
	GCPProductCode    = ""
	GCPAccountID      = ""
	GCPEntitlementID  = ""
	GCPReportID       = ""
	GCPProductUnit    = ""
	GCPCredentialFile = ""
	GCPMarketPlaceSA  = ""
)

func TestGetGCPReportID(t *testing.T) {
	// For test env, has no config file and gcp session. so skip this test.
	t.Skip()
	assert := assert.New(t)
	err := config.Init()
	if err != nil {
		t.Fatal(err)
	}
	viper.Set(config.GCPMarketPlaceProject, GCPProject)
	viper.Set(config.GCPProductCode, GCPProductCode)

	res, err := getGCPReportID(GCPAccountID)
	assert.NoError(err)
	assert.Equal(res, GCPEntitlementID)
}

func TestGCPMetering(t *testing.T) {
	t.Skip()
	assert := assert.New(t)
	err := config.Init()
	assert.NoError(err)

	err = auth.InitWithLocalFile(GCPCredentialFile)
	assert.NoError(err)

	viper.Set(config.GCPMarketPlaceProject, GCPProject)
	viper.Set(config.GCPProductCode, GCPProductCode)
	viper.Set(config.GCPProductUnit, GCPProductUnit)
	viper.Set(config.GCPMarketPlaceSA, GCPMarketPlaceSA)

	handler := GcpPaymentHandlerImpl{}

	invoice := &forms.Invoice{}
	invoice.RawPrice = decimal.NewFromInt(32)

	err = handler.Pay(GCPAccountID, invoice)
	assert.NoError(err)
}
