package model

type MessageTemplateData struct {
	TenantOverviews []*Overview
	DocURL          string
}

type Overview struct {
	Name     string
	Active   int
	Total    int
	Clusters []*ClusterOverview
	Region   string
	PlanType string
	IsPOC    bool
	TenantId uint64
}

type ClusterOverview struct {
	ClusterId           uint64
	MaxQPS              float64
	QPSOver500Min       int
	Status              string
	IsIdle              bool
	NeedPrintPausedHour bool
	PausedHour          float64
}

func (overview *Overview) CalculateClusterCountsAndIsIdle() {
	overview.Total = len(overview.Clusters)
	overview.Active = 0
	for _, cluster := range overview.Clusters {
		if isNormal(cluster.Status) {
			overview.Active++
		}
	}
}

func isNormal(status string) bool {
	activeStatuses := []string{"created", "initializing", "preparing", "launching", "normal", "resuming", "scaling", "upgrading", "recovering"}
	for _, activeStatus := range activeStatuses {
		if status == activeStatus {
			return true
		}
	}
	return false
}

// Sorting related methods
type ByClusterPrior []*Overview

func (overviews ByClusterPrior) Len() int {
	return len(overviews)
}

func (overviews ByClusterPrior) Swap(i, j int) {
	overviews[i], overviews[j] = overviews[j], overviews[i]
}

func (overviews ByClusterPrior) Less(i, j int) bool {
	if overviews[i].Total != overviews[j].Total {
		return overviews[i].Total > overviews[j].Total
	} else {
		return overviews[i].Active > overviews[j].Active
	}
}
