package db

import (
	"fmt"
	"log"
	"poc-daily-report/pkg/model"
	"testing"
	"time"

	"github.com/spf13/viper"
)

func testSetUp() {
	viper.Set("scope", "prod")
	viper.SetConfigName("conf")         // name of config file (without extension)
	viper.SetConfigType("yaml")         // REQUIRED if the config file does not have the extension in the name
	viper.AddConfigPath("../../config") // optionally look for config in the working directory
	err := viper.ReadInConfig()         // Find and read the config file
	if err != nil {                     // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %w \n", err))
	}
}

func TestTimestampType(t *testing.T) {
	testSetUp()
	var ts model.Timestamp
	db, err := getDB()
	if err != nil {
		log.Fatal(err)
	}
	result := db.Last(&ts)
	if result.Error != nil {
		panic(result.Error)
	}
	log.Println("Timestamp:", ts.Timestamp)
}

func TestGetFocusedClusters(t *testing.T) {
	testSetUp()
	clusters, err := GetFocusedClusters(time.Now())
	if err != nil {
		log.Fatal(err)
	}
	log.Println(clusters)
}
