package tests

import (
	"testing"
	"time"

	"github.com/pingcap/dbaas/billing2/utils/log"
	"go.uber.org/zap"

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

	"github.com/pingcap/dbaas/billing2/config"
	"github.com/pingcap/dbaas/billing2/handler/cloudmarketplacehandler/cloudimpl"
)

func TestMeasure(t *testing.T) {
	t.Skip()
	config.Get().SetDefault(config.AZUREMarketplaceTenantID, "6c865c34-8ff8-4792-bbca-8c9d15efb29d")
	config.Get().SetDefault(config.AZUREMarketplaceClientID, "4a52b05d-a34f-4980-baea-d545c7498330")
	config.Get().SetDefault(config.AZUREMarketplaceClientSecret, "s3q8Q~IaMWqWzjpYNCnwXqywtfsV-ke_.OueUbHp")

	handler := &cloudimpl.AzureMarketplaceImpl{}
	client := handler.GetAPIClient()
	//handler.GetSubscription("08cef2d7-a09e-4e56-cacb-09e33d89aff8")
	//handler.GetSubscriptionList()

	request := impl.AzureMeasureRequest{}
	resp := impl.AzureMeasureResponse{}
	start := timeutils.GetHourDate(timeutils.GetNow())

	request.Request = append(request.Request, impl.AzureMeasure{
		ResourceId:         "08cef2d7-a09e-4e56-cacb-09e33d89aff8",
		Quantity:           100,
		Dimension:          "tidb_debug_unit",
		EffectiveStartTime: start.Format(time.RFC3339),
		PlanId:             "debug_plan",
	})

	err := client.Request("POST", "api/batchUsageEvent?api-version=2018-08-31", nil, request, &resp)
	if err != nil {
		log.Error(" failed send measure  ", zap.Error(err))
	} else {
		log.Info("success send measure  ", zap.Any("resp", resp))

	}
}
