package main

import (
	"context"
	"fmt"

	"github.com/tidbcloud/metering/pkg/common/constants"
	"github.com/tidbcloud/metering/pkg/facade"
	"github.com/tidbcloud/metering/pkg/instancemetering"
)

func assertCheckpointPushed(ts int64) {
	ctx := context.TODO()
	// set checkpoint
	checkpoint, err := facade.GetCheckpointReaderWriter(ctx).GetCheckpoint(ctx, constants.ClusterMetaTaskName)
	if err != nil {
		panic(err)
	}
	assert(checkpoint > ts, "checkpoint not pushed")

	checkpoint, err = facade.GetCheckpointReaderWriter(ctx).GetCheckpoint(ctx, constants.BillingTaskName)
	if err != nil {
		panic(err)
	}
	assert(checkpoint > ts, "checkpoint not pushed")

	checkpoint, err = facade.GetCheckpointReaderWriter(ctx).GetCheckpoint(ctx, constants.ReportTaskName)
	if err != nil {
		panic(err)
	}
	assert(checkpoint > ts, "checkpoint not pushed")
}

func assertDataExists(ts int64) {
	ctx := context.TODO()
	file, err := instancemetering.EnsureMeta(ctx, ts)
	assert(err == nil, "cluster meta not exist")
	assert(len(file) > 0, "cluster meta not exist")

	file, err = instancemetering.EnsureBilling(ctx, ts)
	assert(err == nil, "billing data not exist")
	assert(len(file) > 0, "billing data not exist")
}

func assertBillingData(ts int64) {
	ctx := context.TODO()

	file, err := instancemetering.EnsureBilling(ctx, ts)
	assert(err == nil, "GetBillingReportDB failed")

	billingDB, err := instancemetering.GetBillingReportDB(file)
	assert(err == nil, "GetBillingReportDB failed")

	reports, err := billingDB.ListBillingReports(ctx)

	assert(err == nil, "ListBillingReports failed")
	assert(reports[0].CostTimestamp == ts, "CostTimestamp not matched")

	for i, report := range reports {
		assert(report.TenantID == expectedData[i].TenantID, "tenant not equal")
		assert(report.Unit == expectedData[i].Unit, "unit not equal")
		assert(report.Cost == expectedData[i].Cost, "cost not equal")
		assert(report.Labels == expectedData[i].Labels, "labels not equal")
	}

	reportsV2, err := billingDB.ListBillingReportsV2(ctx)
	assert(err == nil, "ListBillingReportsV2 failed")
	assert(len(reportsV2) == len(reports), "ListBillingReportsV2 length not equal to ListBillingReports")
	for _, report := range reportsV2 {
		var marched = false
		for _, expected := range expectedDataV2 {
			if report.TenantID == expected.TenantID && report.Unit == expected.Unit && report.UnitValue == expected.UnitValue && report.Cost == expected.Cost && report.Labels == expected.Labels {
				marched = true
				break
			}
		}
		if !marched {
			panic(fmt.Sprintf("not found matched report, report is %v", report))
		}
	}
}

func assert(assertion bool, errMsg string) {
	if !assertion {
		panic(errMsg)
	}
}

var expectedData = []Expected{
	// available cluster, tikv node
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 3, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// available cluster, tikv disk
	{20003, "disk-storage:aws:us-west-2:gp3", 30, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{20003, "disk-iops:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{20003, "disk-throughput:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// available cluster, tidb node, without disk
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 2, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIDB\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"0\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"0\"}"},

	// available cluster, tiflash node
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 1, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// available cluster, tiflash disk
	{20003, "disk-storage:aws:us-west-2:gp3", 10, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{20003, "disk-iops:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{20003, "disk-throughput:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-available\",\"clusterID\":\"20001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"20002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// paused cluster, only disk metered
	{40003, "disk-storage:aws:us-west-2:gp3", 30, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{40003, "disk-iops:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{40003, "disk-throughput:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{40003, "disk-storage:aws:us-west-2:gp3", 10, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{40003, "disk-iops:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{40003, "disk-throughput:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-paused\",\"clusterID\":\"40001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"40002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// resuming cluster, only disk metered
	{50003, "disk-storage:aws:us-west-2:gp3", 30, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{50003, "disk-iops:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{50003, "disk-throughput:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{50003, "disk-storage:aws:us-west-2:gp3", 10, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{50003, "disk-iops:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{50003, "disk-throughput:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-resuming\",\"clusterID\":\"50001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"50002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// pausing cluster, only disk metered
	{70003, "disk-storage:aws:us-west-2:gp3", 30, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{70003, "disk-iops:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{70003, "disk-throughput:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{70003, "disk-storage:aws:us-west-2:gp3", 10, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{70003, "disk-iops:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{70003, "disk-throughput:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-pausing\",\"clusterID\":\"70001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"70002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// scaling cluster, 2 tidb t4g.medium, 1 tidb t4g.large
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 3, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIDB\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"0\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"0\"}"},
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.large", 1, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIDB\",\"cpuNum\":\"4\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"0\",\"memoryGiB\":\"8\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"0\"}"},

	// scaling cluster, 3 tikv available
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 3, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// scaling cluster, tikv disk
	{80003, "disk-storage:aws:us-west-2:gp3", 30, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{80003, "disk-iops:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{80003, "disk-throughput:aws:us-west-2:gp3", 3, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIKV\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// scaling cluster, 1 COMPONENT_TYPE_TIFLASH
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", 1, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},

	// scaling cluster, tikv disk
	{80003, "disk-storage:aws:us-west-2:gp3", 10, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{80003, "disk-iops:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
	{80003, "disk-throughput:aws:us-west-2:gp3", 1, "{\"cluster\":\"test-scaling\",\"clusterID\":\"80001\",\"component\":\"COMPONENT_TYPE_TIFLASH\",\"cpuNum\":\"2\",\"crossAccount\":\"false\",\"devTier\":\"false\",\"iops\":\"4000\",\"memoryGiB\":\"4\",\"poc\":\"false\",\"projectID\":\"80002\",\"provider\":\"aws\",\"throughput\":\"400\"}"},
}

var expectedDataV2 = []ExpectedV2{
	// available cluster, tikv node
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 3, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIKV","projectID":"20002","provider":"aws"}`},

	// available cluster, tikv disk
	{20003, "disk-iops:aws:us-west-2:gp3", "4000", 3, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIKV","projectID":"20002","provider":"aws"}`},
	{20003, "disk-throughput:aws:us-west-2:gp3", "400", 3, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIKV","projectID":"20002","provider":"aws"}`},
	{20003, "disk-storage:aws:us-west-2:gp3", "10", 3, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIKV","projectID":"20002","provider":"aws"}`},

	// available cluster, tidb node, without disk
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 2, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIDB","projectID":"20002","provider":"aws"}`},

	// available cluster, tiflash node
	{20003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 1, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIFLASH","projectID":"20002","provider":"aws"}`},

	// available cluster, tiflash disk
	{20003, "disk-iops:aws:us-west-2:gp3", "4000", 1, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIFLASH","projectID":"20002","provider":"aws"}`},
	{20003, "disk-throughput:aws:us-west-2:gp3", "400", 1, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIFLASH","projectID":"20002","provider":"aws"}`},
	{20003, "disk-storage:aws:us-west-2:gp3", "10", 1, `{"clusterID":"20001","component":"COMPONENT_TYPE_TIFLASH","projectID":"20002","provider":"aws"}`},

	// paused cluster, only disk metered
	{40003, "disk-iops:aws:us-west-2:gp3", "4000", 3, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIKV","projectID":"40002","provider":"aws"}`},
	{40003, "disk-throughput:aws:us-west-2:gp3", "400", 3, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIKV","projectID":"40002","provider":"aws"}`},
	{40003, "disk-storage:aws:us-west-2:gp3", "10", 3, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIKV","projectID":"40002","provider":"aws"}`},
	{40003, "disk-storage:aws:us-west-2:gp3", "10", 1, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIFLASH","projectID":"40002","provider":"aws"}`},
	{40003, "disk-iops:aws:us-west-2:gp3", "4000", 1, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIFLASH","projectID":"40002","provider":"aws"}`},
	{40003, "disk-throughput:aws:us-west-2:gp3", "400", 1, `{"clusterID":"40001","component":"COMPONENT_TYPE_TIFLASH","projectID":"40002","provider":"aws"}`},

	// resuming cluster, only disk metered
	{50003, "disk-iops:aws:us-west-2:gp3", "4000", 3, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIKV","projectID":"50002","provider":"aws"}`},
	{50003, "disk-throughput:aws:us-west-2:gp3", "400", 3, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIKV","projectID":"50002","provider":"aws"}`},
	{50003, "disk-storage:aws:us-west-2:gp3", "10", 3, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIKV","projectID":"50002","provider":"aws"}`},
	{50003, "disk-storage:aws:us-west-2:gp3", "10", 1, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIFLASH","projectID":"50002","provider":"aws"}`},
	{50003, "disk-iops:aws:us-west-2:gp3", "4000", 1, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIFLASH","projectID":"50002","provider":"aws"}`},
	{50003, "disk-throughput:aws:us-west-2:gp3", "400", 1, `{"clusterID":"50001","component":"COMPONENT_TYPE_TIFLASH","projectID":"50002","provider":"aws"}`},

	// pausing cluster, only disk metered
	{70003, "disk-iops:aws:us-west-2:gp3", "4000", 3, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIKV","projectID":"70002","provider":"aws"}`},
	{70003, "disk-throughput:aws:us-west-2:gp3", "400", 3, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIKV","projectID":"70002","provider":"aws"}`},
	{70003, "disk-storage:aws:us-west-2:gp3", "10", 3, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIKV","projectID":"70002","provider":"aws"}`},
	{70003, "disk-throughput:aws:us-west-2:gp3", "400", 1, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIFLASH","projectID":"70002","provider":"aws"}`},
	{70003, "disk-storage:aws:us-west-2:gp3", "10", 1, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIFLASH","projectID":"70002","provider":"aws"}`},
	{70003, "disk-iops:aws:us-west-2:gp3", "4000", 1, `{"clusterID":"70001","component":"COMPONENT_TYPE_TIFLASH","projectID":"70002","provider":"aws"}`},

	// scaling cluster, 2 tidb t4g.medium, 1 tidb t4g.large
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 3, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIDB","projectID":"80002","provider":"aws"}`},
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.large", "1", 1, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIDB","projectID":"80002","provider":"aws"}`},

	// scaling cluster, 3 tikv available
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 3, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIKV","projectID":"80002","provider":"aws"}`},

	// scaling cluster, tikv disk
	{80003, "disk-storage:aws:us-west-2:gp3", "10", 3, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIKV","projectID":"80002","provider":"aws"}`},
	{80003, "disk-iops:aws:us-west-2:gp3", "4000", 3, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIKV","projectID":"80002","provider":"aws"}`},
	{80003, "disk-throughput:aws:us-west-2:gp3", "400", 3, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIKV","projectID":"80002","provider":"aws"}`},

	// scaling cluster, 1 COMPONENT_TYPE_TIFLASH
	{80003, "node:aws:us-west-2:DEPLOY_TYPE_DEDICATED:t4g.medium", "1", 1, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIFLASH","projectID":"80002","provider":"aws"}`},

	// scaling cluster, tikv disk
	{80003, "disk-iops:aws:us-west-2:gp3", "4000", 1, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIFLASH","projectID":"80002","provider":"aws"}`},
	{80003, "disk-throughput:aws:us-west-2:gp3", "400", 1, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIFLASH","projectID":"80002","provider":"aws"}`},
	{80003, "disk-storage:aws:us-west-2:gp3", "10", 1, `{"clusterID":"80001","component":"COMPONENT_TYPE_TIFLASH","projectID":"80002","provider":"aws"}`},
}

type Expected struct {
	TenantID uint64
	Unit     string
	Cost     int64
	Labels   string
}

type ExpectedV2 struct {
	TenantID  uint64
	Unit      string
	UnitValue string
	Cost      int64
	Labels    string
}
