package main

import (
	"testing"
	"time"

	"github.com/pingcap-inc/clinic/clinic_data_service/pkg/dto"
	log2 "github.com/pingcap-inc/clinic/clinic_data_service/pkg/log"
	"github.com/pingcap-inc/clinic/clinic_data_service/pkg/parser"
	"github.com/pingcap-inc/clinic/clinic_data_service/pkg/service"
	"github.com/pingcap-inc/clinic/clinic_data_service/pkg/thirdapi/sqlstatement"

	"go.uber.org/zap"
)

func TestParseStatStatements(t *testing.T) {
	Init()

	// filename := "/Users/wlt/statements_saas05_0828.json"
	filename := "/Users/wlt/Documents/GolandProjects/clinic/health_check/clinic_data_service/output/statements/ap_0905_11-13.json"
	clusterId := "1379661944646416027"
	queryTimeStr := "2025-08-28T11:00:00Z"
	promSqlTime := "12h"
	if err := parser.StatStatements(filename, clusterId, queryTimeStr, promSqlTime); err != nil {
		log2.PlainError("fail", zap.String("file", filename), zap.Error(err))
	}
}
func TestSqlStatements(t *testing.T) {
	Init()

	top := 10
	// cookie := "clinic.session_id=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTc0OTE0ODQsInVzZXIiOnsiZW1haWwiOiJsZXRpYW4ud2FuZ0BwaW5nY2FwLmNvbSIsInVzZXJuYW1lIjoibGV0aWFuLndhbmdAcGluZ2NhcC5jb20iLCJjc3JmVG9rZW4iOiJTaWxzVDJRb0REQkRaaUlRIn19.Mp6KE5bXBlL3q9ucf5aLBJBfEOiq46fVNBugkk0qK6k"
	cookie := "clinic.session_id=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NjIwMDU1NTksInVzZXIiOnsiZW1haWwiOiJsZXRpYW4ud2FuZ0BwaW5nY2FwLmNvbSIsInVzZXJuYW1lIjoibGV0aWFuLndhbmdAcGluZ2NhcC5jb20iLCJjc3JmVG9rZW4iOiJ0TVhmZWM2WFNsTzhsdVpqIn19.XBP2YYvdHRpoHt-qS4XZ2hAnLKkn7YRBMzgh7ybp0Sg"
	// clusterIdA := "10956278120794001035" // gogame-poc
	// clusterAStartTime, _ := time.Parse(time.RFC3339, "2025-10-23T06:45:00Z")
	// clusterAEndTime, _ := time.Parse(time.RFC3339, "2025-10-24T02:00:00Z")

	clusterIdB := "1379661944646414653" // gogame
	clusterBStartTime, _ := time.Parse(time.RFC3339, "2025-10-20T07:11:58Z")
	clusterBEndTime, _ := time.Parse(time.RFC3339, "2025-10-21T02:26:58Z")
	var cs []service.ClusterInfo
	// cs = append(cs, service.ClusterInfo{
	// 	ClusterId: clusterIdA,
	// 	TimeRange: dto.TimeRange{
	// 		Start:     clusterAStartTime,
	// 		StartUnix: clusterAStartTime.UTC().Unix(),
	// 		End:       clusterAEndTime,
	// 		EndUnix:   clusterAEndTime.UTC().Unix(),
	// 	},
	// })
	cs = append(cs, service.ClusterInfo{
		ClusterId: clusterIdB,
		TimeRange: dto.TimeRange{
			Start: clusterBStartTime,
			// StartUnix: clusterBStartTime.UTC().Unix(),
			End: clusterBEndTime,
			// EndUnix:   clusterBEndTime.UTC().Unix(),
		},
	})

	_, err := sqlstatement.FetchStatementsAndCountSchema(cs, cookie, top)
	if err != nil {
		log2.PlainError("fail", zap.Strings("cluster_ids", []string{clusterIdB}), zap.Error(err))
	}
	log2.PlainInfo("done........")
	// for _, r := range results {
	// 	log2.PlainInfo("result", zap.Any("resp", r))
	// }

}
