package webScene

import (
	"github.com/stretchr/testify/assert"
	"testing"

	l4g "github.com/alecthomas/log4go"
	"github.com/dailymotion/allure-go"
	"github.com/tidbcloud/qa-PlatformAPIAuto/common"
)

func (w *WebE2ECase) OldGcpCheckRecycleBin(t *testing.T) {
	var provider = "gcp"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestGcpCheckRecycleBin"),
		allure.Feature("CheckRecycleBin"),
		allure.Description("CheckRecycleBin"),
		allure.Action(func() {
			backupId := common.CheckRecycleBin(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
			if backupId != "" {
				w.WebRequestInfo.Cluster.ClusterId = backupId
			}
		}))
}

func (w *WebE2ECase) OldGcpBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "gcp"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestGcpBackupOperation"),
		allure.Feature("CheckBackupOperation"),
		allure.Description("CheckBackupOperation"),
		allure.Action(func() {
			common.CheckStandardBackupOperation(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldGcpLogBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "gcp"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestGcpLogBackupOperation"),
		allure.Feature("CheckLogBackupOperation"),
		allure.Description("CheckLogBackupOperation"),
		allure.Action(func() {
			common.CheckLogBackup(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldGcpDualRegionAndLogBackupBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "gcp"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestGcpDualRegionBackupOperation"),
		allure.Feature("CheckDualRegionBackupOperation"),
		allure.Description("CheckDualRegionBackupOperation"),
		allure.Action(func() {
			common.CheckDualRegionBackup(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldAwsDualRegionAndLogBackupBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "aws"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestAwsDualRegionBackupOperation"),
		allure.Feature("CheckDualRegionBackupOperation"),
		allure.Description("CheckDualRegionBackupOperation"),
		allure.Action(func() {
			common.CheckDualRegionBackup(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldAwsCheckRecycleBin(t *testing.T) {
	var provider = "aws"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	l4g.Info("clusterId:%s", clusterId)
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestAwsCheckRecycleBin"),
		allure.Feature("CheckRecycleBin"),
		allure.Description("CheckRecycleBin"),
		allure.Action(func() {
			backupId := common.CheckRecycleBin(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
			if backupId != "" {
				w.WebRequestInfo.Cluster.ClusterId = backupId
			}

		}))
}

func (w *WebE2ECase) OldAwsBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "aws"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestBackupOperation"),
		allure.Feature("CheckBackupOperation"),
		allure.Description("CheckBackupOperation"),
		allure.Action(func() {
			common.CheckStandardBackupOperation(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldAwsEKSEBSOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "aws"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestEBSBackupOperation"),
		allure.Feature("TestEBSBackupOperation"),
		allure.Description("TestEBSBackupOperation"),
		allure.Action(func() {
			common.CheckEBSBackupOperation(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) OldAwsLogBackupOperation(t *testing.T) {
	w.WebRequestInfo.SetTimeZone(0)
	var provider = "aws"
	clusterId := w.WebRequestInfo.Cluster.ClusterId
	tidbCount := w.WebRequestInfo.Cluster.TiDBNodeCount
	tikvCount := w.WebRequestInfo.Cluster.TiKVNodeCount
	tiflashCount := w.WebRequestInfo.Cluster.TiFlashNodeCount
	allure.Test(t,
		allure.Epic("TestLogBackupOperation"),
		allure.Feature("CheckLogBackupOperation"),
		allure.Description("CheckLogBackupOperation"),
		allure.Action(func() {
			common.CheckLogBackup(t, "", clusterId, provider, false, tidbCount, tikvCount, tiflashCount)
		}))
}

func (w *WebE2ECase) AwsDataMigration(t *testing.T) {
	var provider = "aws"
	allure.Test(t,
		allure.Epic("AwsDataMigration"),
		allure.Feature("PhysicalDataMigration"),
		allure.Description("PhysicalDataMigration"),
		allure.Action(func() {
			common.DataMigration(t, provider, w.WebRequestInfo.Cluster.ClusterId, "public", "physical")
		}))

	allure.Test(t,
		allure.Epic("AwsDataMigration"),
		allure.Feature("LogicalDataMigration"),
		allure.Description("LogicalDataMigration"),
		allure.Action(func() {
			common.DataMigration(t, provider, w.WebRequestInfo.Cluster.ClusterId, "public", "logical")
		}))
}

func (w *WebE2ECase) AwsVpcPeeringDataMigration(t *testing.T) {
	if w.WebRequestInfo.Cluster.Region != "us-west-2" {
		w.SetReporter(t)
		w.Reporter.SceneReport(func() {
			w.Reporter.StepReport("only support us-west-2 region!", func() {
				assert.True(t, false)
			})
		})
		return
	}
	var provider = "aws"
	var vpcId string
	allure.Test(t,
		allure.Epic("AwsVpcPeeringDataMigration"),
		allure.Feature("CreateVpcPeering"),
		allure.Description("CreateVpcPeering"),
		allure.Action(func() {
			_, vpcId = w.createAWSVpcPeeringUntilActive(true)
		}))
	allure.Test(t,
		allure.Epic("AwsVpcPeeringDataMigration"),
		allure.Feature("DataMigration"),
		allure.Description("DataMigration"),
		allure.Action(func() {
			common.DataMigration(t, provider, w.WebRequestInfo.Cluster.ClusterId, "vpc-peering", "logical")
		}))

	allure.Test(t,
		allure.Epic("AwsVpcPeeringDataMigration"),
		allure.Feature("DeleteVpcPeering"),
		allure.Description("DeleteVpcPeering"),
		allure.Action(func() {
			w.deleteVpcPeering(vpcId)
		}))
}

func (w *WebE2ECase) GcpDataMigration(t *testing.T) {
	var provider = "gcp"
	allure.Test(t,
		allure.Epic("GcpDataMigration"),
		allure.Feature("PhysicalDataMigration"),
		allure.Description("PhysicalDataMigration"),
		allure.Action(func() {
			common.DataMigration(t, provider, w.WebRequestInfo.Cluster.ClusterId, "public", "physical")
		}))

	allure.Test(t,
		allure.Epic("GcpDataMigration"),
		allure.Feature("LogicalDataMigration"),
		allure.Description("LogicalDataMigration"),
		allure.Action(func() {
			common.DataMigration(t, provider, w.WebRequestInfo.Cluster.ClusterId, "public", "logical")
		}))
}
