package dto

import (
	"github.com/prometheus/common/model"
)

// TestDiffResult represents the test diff result structure
type DiffResult struct {
	Key     string       `json:"Key"`
	Metrics []DiffMetric `json:"Metrics"` // Note: keeping original spelling "Metrcis"
}

// TestDiffMetric represents a single metric with tag, aggregation and points
type DiffMetric struct {
	Tag         string          `json:"Tag"`
	Aggregation DiffAggregation `json:"Aggregation"`
	Points      []DiffPoint     `json:"Points"`
}

// TestDiffAggregation contains aggregation values (Max, Avg, etc.)
type DiffAggregation struct {
	Max *DiffAggregationValue `json:"Max,omitempty"`
	Avg *DiffAggregationValue `json:"Avg,omitempty"`
}

// TestDiffAggregationValue contains values for both clusters and the difference
type DiffAggregationValue struct {
	ClusterA string  `json:"ClusterA"`
	ClusterB string  `json:"ClusterB"`
	Diff     float64 `json:"Diff"`
}

// TestDiffPoint represents a single time point with values from both clusters
type DiffPoint struct {
	TimeA                 string  `json:"Time"`
	ClusterA              float64 `json:"ClusterA"`
	TimeB                 string  `json:"TimeB"`
	ClusterB              float64 `json:"ClusterB"`
	ClusterAUnixTimestamp int64   `json:"ClusterAUnixTimestamp"`
	ClusterBUnixTimestamp int64   `json:"ClusterBUnixTimestamp"`
}

type MetricsCompareResponse struct {
	DiffClusters ClusterDiffInfoTest `json:"DiffClusters"`
	Units        []string            `json:"Units,omitempty"`
	Result       Result              `json:"result"`
	ClusterDiff  []DiffResult        `json:"ClusterDiff"`
}

type ClusterDiffInfoTest struct {
	ClusterA string `json:"ClusterA"`
	ClusterB string `json:"ClusterB"`
}

type ClusterSet struct {
	ClusterA model.Value
	ClusterB model.Value
}

type ClusterData struct {
	QueryName  string
	ClusterSet ClusterSet
}

//	type CompareRequest struct {
//		TestClusterID string    `json:"testClusterId"` // Test cluster ID
//		ProdClusterID string    `json:"prodClusterId"` // Production cluster ID
//		ProdStartTime time.Time `json:"prodStartTime"` // Production start time
//		ProdEndTime   time.Time `json:"prodEndTime"`   // Production end time
//		TestStartTime time.Time `json:"testStartTime"` // Test start time
//		TestEndTime   time.Time `json:"testEndTime"`   // Test end time
//		Interval      string    `json:"interval"`
//		DiffKeys      []string  `json:"diffKeys,omitempty"` // Optional: filter queries by keys, empty means all queries
//		CsvDir        string    `json:"csvDir,omitempty"`   // Optional: output directory for CSV files, empty means no CSV output
//		ClusterAUrls   ClusterUrls `json:"clusterAUrls,omitempty"`
//		ClusterBUrls   ClusterUrls `json:"clusterBUrls,omitempty"`
//	}
type CompareRequest struct {
	ClusterA     ClusterSideDTO `json:"clusterA"`
	ClusterB     ClusterSideDTO `json:"clusterB"`
	Interval     string         `json:"interval"`
	DiffKeys     []string       `json:"diffKeys,omitempty"` // Optional: filter queries by keys, empty means all queries
	CsvDir       string         `json:"csvDir,omitempty"`   // Optional: output directory for CSV files, empty means no CSV output
	// ClusterAUrls ClusterUrls    `json:"clusterAUrls,omitempty"`
	// ClusterBUrls ClusterUrls    `json:"clusterBUrls,omitempty"`
}

type ClusterUrls struct {
	ClusterMetricsURL   string `json:"clusterMetricsUrl,omitempty"`
	DataPlaneMetricsURL string `json:"dataPlaneMetricsUrl,omitempty"`
	SlowQueryS3URL      string `json:"slowQueryS3Url,omitempty"`
}
