package dao

import "gorm.io/gorm"

var (
	db      *gorm.DB
	unifyDB *gorm.DB
	corpDB  *gorm.DB
)

type CountValue struct {
	Key   string `json:"key"`
	Name  string `json:"name"`
	Value int64  `json:"value"`
}

type SortCountValue []*CountValue

func (a SortCountValue) Len() int {
	return len(a)
}

func (a SortCountValue) len() int {
	return len(a)
}

func (a SortCountValue) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a SortCountValue) Less(i, j int) bool {
	return a[i].Value > a[j].Value
}

func SetDB(d *gorm.DB) {
	db = d
}

func SetUnifyDB(d *gorm.DB) {
	unifyDB = d
}
func SetCorpDB(d *gorm.DB) {
	corpDB = d
}

func GetDB() *gorm.DB {
	return db
}