package tests

import (
	"testing"

	"github.com/pingcap/dbaas/billing2/handler/paymenthandler/impl"

	"github.com/pingcap/dbaas/billing2/config"
	"github.com/pingcap/dbaas/billing2/db"
	"github.com/pingcap/dbaas/billing2/db/entity"
	"github.com/pingcap/dbaas/billing2/utils/tests"
	"github.com/shopspring/decimal"
	"github.com/stretchr/testify/suite"
)

type GCPReconciliationTestTestSuit struct {
	tests.BillingTestSuite
}

func TestGCPReconciliationTestTestSuit(t *testing.T) {
	suite.Run(t, new(GCPReconciliationTestTestSuit))
}

func (s *GCPReconciliationTestTestSuit) TestParse() {
	assert := s.Assert()
	config.Get().Set(config.GCPProductSKUID, "4426-A355-AB25")
	err := (&entity.PaymentMethod{
		PaymentType: entity.PaymentType_GCP,
		PaymentCode: "4e042453-361a-45b2-816d-f2c3e89c642a",
	}).Create(db.GetDB())
	assert.NoError(err)
	gcpHandler := &impl.GcpPaymentHandlerImpl{}
	result, err := gcpHandler.ParseGCPReport([]byte(TestGCPInput))
	assert.NoError(err)
	assert.Len(result, 5)
	cnt := 0
	for _, res := range result {
		if res.PaymentCode == "4e042453-361a-45b2-816d-f2c3e89c642a" {
			assert.Equal(decimal.RequireFromString("796.46"), res.Revenue)
			cnt++
		}
	}
	assert.Equal(1, cnt)
}
