package helper

import (
	"encoding/base64"
	"fmt"
	"testing"
	"time"
)

func TestHashMod(t *testing.T) {
	serverId := HashMod("1dfsfdsfsddf12dddd5451212iodewnsanf2")
	fmt.Println(serverId)
}

func TestNoticeTime(t *testing.T) {
	now := time.Now()

	// 获取七天前的日期
	noticeStartDay := now.AddDate(0, 0, -15)
	// 获取七天前 00:00:00 的时间
	startTime := time.Date(noticeStartDay.Year(), noticeStartDay.Month(), noticeStartDay.Day(), 0, 0, 0, 0, noticeStartDay.Location())

	noticeEndDay := now.AddDate(0, 0, -1)
	// 获取昨天 23:59:59 的时间
	endTime := time.Date(noticeEndDay.Year(), noticeEndDay.Month(), noticeEndDay.Day(), 23, 59, 59, 0, noticeEndDay.Location())

	t.Logf("startTime:%s,endTime:%s", startTime, endTime)
}

func TestNum(t *testing.T) {
	useNum := 0
	used(&useNum)
	t.Log(useNum)
}

func used(useNum *int) {
	queryUsed(useNum)
	queryUsed(useNum)
	*useNum += 1
}

func queryUsed(useNum *int) {
	*useNum += 1
}

func TestMd5(t *testing.T) {

	jsonStr := `{"content":"1","timestamp":1765447477945,"ciphertext":"77CAC2FCFDEBAC6665025A1B81E3BBF9"}`

	ciphertext := Md5(jsonStr)
	t.Log(ciphertext)
}

func Test_DecodeString(t *testing.T) {
	wxNotifyData, _ := base64.StdEncoding.DecodeString("ewogICJpZCI6ICI0YWIyNjk5ZC1lOTFkLTU0NjAtOTgxMC0yNWZkNmQ0YzY5YTUiLAogICJjcmVhdGVfdGltZSI6ICIyMDI1LTEyLTA4VDE3OjU0OjI0KzA4OjAwIiwKICAicmVzb3VyY2VfdHlwZSI6ICJlbmNyeXB0LXJlc291cmNlIiwKICAiZXZlbnRfdHlwZSI6ICJDT1VQT04uVVNFIiwKICAic3VtbWFyeSI6ICLku6Pph5HliLjmoLjplIDpgJrnn6UiLAogICJvcmlnaW5hbF90eXBlIjogImNvdXBvbiIsCiAgImFzc29jaWF0ZWRfZGF0YSI6ICJjb3Vwb24iLAogICJwbGFpbl90ZXh0IjogewogICAgInN0b2NrX2NyZWF0b3JfbWNoaWQiOiAiMTY1MjQ2NTU0MSIsCiAgICAic3RvY2tfaWQiOiAiMjEzODY0ODQiLAogICAgImNvdXBvbl9pZCI6ICIxNDIzODgzNTQ5OTQiLAogICAgImNvdXBvbl9uYW1lIjogIumTtuihjOWNoeWkmueslOeri+WHjyIsCiAgICAiZGVzY3JpcHRpb24iOiAiIiwKICAgICJzdGF0dXMiOiAiU0VOREVEIiwKICAgICJjcmVhdGVfdGltZSI6ICIyMDI1LTEyLTA4VDE3OjUwOjQ4KzA4OjAwIiwKICAgICJjb3Vwb25fdHlwZSI6ICJOT1JNQUwiLAogICAgIm5vX2Nhc2giOiBmYWxzZSwKICAgICJzaW5nbGVpdGVtIjogZmFsc2UsCiAgICAiYnVzaW5lc3NfdHlwZSI6ICIiLAogICAgImNvbnN1bWVfaW5mb3JtYXRpb24iOiB7CiAgICAgICJjb25zdW1lX3RpbWUiOiAiMjAyNS0xMi0wOFQxNzo1NDoyNCswODowMCIsCiAgICAgICJjb25zdW1lX21jaGlkIjogIjEyNzQ5Mzg2MDEiLAogICAgICAidHJhbnNhY3Rpb25faWQiOiAiNDIwMDAwMjk5NjIwMjUxMjA4MzA2MzA1MTgzNCIsCiAgICAgICJjb25zdW1lX2Ftb3VudCI6IDE2CiAgICB9CiAgfQp9")
	t.Log(string(wxNotifyData))
}

func TestLength(t *testing.T) {

	jsonStr := `{
  "id": "4ab2699d-e91d-5460-9810-25fd6d4c69a5",
  "create_time": "2025-12-08T17:54:24+08:00",
  "resource_type": "encrypt-resource",
  "event_type": "COUPON.USE",
  "summary": "代金券核销通知",
  "original_type": "coupon",
  "associated_data": "coupon",
  "plain_text": {
    "stock_creator_mchid": "1652465541",
    "stock_id": "21386484",
    "coupon_id": "142388354994",
    "coupon_name": "银行卡多笔立减",
    "description": "",
    "status": "SENDED",
    "create_time": "2025-12-08T17:50:48+08:00",
    "coupon_type": "NORMAL",
    "no_cash": false,
    "singleitem": false,
    "business_type": "",
    "consume_information": {
      "consume_time": "2025-12-08T17:54:24+08:00",
      "consume_mchid": "1274938601",
      "transaction_id": "4200002996202512083063051834",
      "consume_amount": 16
    }
  }
}`
	s := len(jsonStr)
	t.Log(s)
}

func Test_Time(t *testing.T) {

	strTime := "2026-03-27 10:33:20"
	tt, _ := time.Parse("2006-01-02 15:04:05", strTime)
	t.Log(tt.Format("2006-01-02 15:04:05.000"))

	//for i := 0; i < 20; i++ {
	//	formatTime := time.Now().Format("2006-01-02 15:04:05.999")
	//	t.Log(formatTime)
	//	formatTime2 := time.Now().Format("2006-01-02 15:04:05.000")
	//	t.Log(formatTime2)
	//	time.Sleep(1 * time.Second)
	//}
}
