package main

import (
	"context"
	"fmt"
	"time"

	"github.com/pingcap-inc/clinic/pkg/ngm/slowquery"
	"github.com/pingcap-inc/clinic/pkg/ngm/storage"
)

func main() {
	stores, err := storage.NewStorageFactory("arn:aws:iam::557537366020:role/clinic-staging-read-s3")
	check(err)
	sq := slowquery.NewSlowQueryV2(stores)
	clusterIds := []string{
		"1379661944646413143", // prod-us-saas-tidb
		"1379661944646413655", // prod-us-saas-region02-tidb
		"1379661944646413999", // prod-us-saas-region03-tidb
		"1379661944646413150", // us-betcenter-order-prod
		"1379661944646413610", // us-betcenter-order-prod-02
		"1379661944646414132", // us-betcenter-order-prod-03
		"1379661944646413411", // us-seamless-walletcenter-prod
		"1379661944646414267", // prod-seamless-wallet-02
	}
	hoursList := []int{1, 3, 6, 12, 24, 72, 168}
	for _, clusterId := range clusterIds {
		fmt.Println(clusterId)
		fmt.Println()
		for _, hours := range hoursList {
			for n := 0; n < 3; n++ {
				fmt.Printf("%d hours\n", hours)
				begin := time.Now()
				logs, err := sq.List(context.TODO(), &slowquery.ListParams{
					Provider:   "aws",
					Region:     "us-east-1",
					TenantID:   "",
					ProjectID:  "",
					ClusterID:  "1379661944646413143",
					SharedTier: false,

					BeginTime: 1714264200 - 3600*hours,
					EndTime:   1714264200,
					Limit:     100,
					OrderBy:   "query_time",
					Text:      "",
					Digest:    "",
					DB:        []string{},
					Plans:     []string{},
					IsDesc:    true,
				})
				check(err)
				fmt.Println(len(logs))
				fmt.Println(time.Since(begin))
				fmt.Println()
			}
		}
	}
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}
