package mhayaSlice

import (
	"fmt"
	mhayaString "github.com/mhaya/extend/string"
	mhayaTime "github.com/mhaya/extend/time"
	"slices"
	"testing"
	"time"
)

//func TestUnique(t *testing.T) {
//	list := Unique[string]("1", "2", "3", "1")
//	fmt.Println(list)
//}

var currentTime = int64(1727686800)

func TestUniques(t *testing.T) {
	//s1 := []string{"1", "2", "3"}
	//s2 := []string{"1", "2", "3"}
	//
	//list := Uniques[string](s1, s2)
	//fmt.Println(list)

	// 上次恢复时间
	var roolDay = int64(0)

	for i := 0; i < 10; i++ {
		RefreshRoll(&roolDay)
	}

}

func RefreshRoll(roolDay *int64) bool {
	arr := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}
	slice := make([]int, 0)
	for _, s := range arr {
		hour, _ := mhayaString.ToInt(s)
		slice = append(slice, hour)
	}

	rollHour := time.Unix(*roolDay, 0).Hour()

	// 小时数，24小时制
	//curHour := time.Now().Hour()
	curHour := 17
	if curHour == 0 {
		curHour = 24
	}

	if rollHour == 0 {
		rollHour = 24
	}

	isToday := mhayaTime.CreateFromTimestamp(*roolDay).IsToday()
	isTomorrow := mhayaTime.CreateFromTimestamp(*roolDay).IsTomorrow()

	// 昨天的24点isToday为true，所以24点必须单独处理
	if (rollHour == 24 && isTomorrow) || (rollHour != 24 && isToday) {
		slice = slices.DeleteFunc(slice, func(x int) bool {
			return x <= rollHour
		})
	}

	fmt.Println("slice:", slice)
	if slices.Contains(slice, curHour) {
		*roolDay = currentTime
		fmt.Println(" execute ==> num := p.Item[ItemRoll].AddSameTwo()")
		return true
	}
	return false
}
