package impl

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/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)
	}
	config.Get().Set(config.GCPMarketPlaceProject, GCPProject)
	config.Get().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)

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

	handler := GcpPaymentHandlerImpl{}

	invoice := &forms.Invoice{}
	invoice.RawPrice = decimal.NewFromInt(32)
	payment := &forms.PaymentMethod{PaymentCode: GCPAccountID}
	_, err = handler.Pay(payment, nil, invoice)
	assert.NoError(err)
}
