package hashgen

import (
	"encoding/hex"
	"fmt"
	"testing"
	"time"

	"github.com/sirupsen/logrus"
	"gogs.daxia.dev/huanan/pkg.daxia.dev/encrypt"
	"gogs.daxia.dev/huanan/pkg.daxia.dev/time_utils"
)

func TestHash256(t *testing.T) {
	hashItem := encrypt.KeyDataSHA256([]byte("0443b45db5e612611b9fd76f3d815c6fb7ea0ff869b5a920882da59062d24dcf"))
	if hex.EncodeToString(hashItem) != "cbfdc47bd53a50b3ad437f203c2f0086f47dbc0632223c574728f35161031b5e" {
		t.Fatal(hex.EncodeToString(hashItem))
	}
}

func TestGetOpennum(t *testing.T) {
	go Init()
	<-time.After(3 * time.Second)

	logrus.Info("start...")

	timeNow := time.Now()
	today := time_utils.GetFormatTime(timeNow)
	cardList, hashstr, err := GetOpenNumber(today, 1, []byte("1234"), 0)
	if err != nil {
		t.Fatal(err)
	}

	fmt.Println(cardList)
	fmt.Println(hashstr)
}

func TestGetRoomHash(t *testing.T) {
	hashHex, _ := hex.DecodeString("471062dc2ec6f8c08b36ba82b1a8db00e1de2af1e61e1f7462727510b46da4d4")

	roomHash := getRoomHash(hashHex, 2)
	fmt.Println(hex.EncodeToString(roomHash))
}
