package multisend

import (
	"context"
	"encoding/json"
	"testing"
	"time"

	"github.com/google/uuid"
)

func TestRateLimit(t *testing.T) {

	// client:= initClient(10)

	// ctx := context.Background()
	// limiter := redis_rate.NewLimiter(client)

	// for i := 0; i < 10; i++ {
	// 	res, err := limiter.Allow(ctx, "project:123", redis_rate.PerSecond(10))
	// 	if err != nil {
	// 		panic(err)
	// 	}

	// 	client.Set(ctx, "key", i, time.Second*100)
	// 	fmt.Println("allowed", res.Allowed, "remaining", res.Remaining)

	// }

}

type Person struct {
	Name string `json:"name"`
	Age  int64  `json:"age"`
}

func TestSetGetJson(t *testing.T) {
	client := initClient(10, "13.40.18.11:6379", "redis20220217")

	id := uuid.New()

	p1 := Person{
		Name: "alice",
		Age:  10,
	}

	p1AsJson, err := json.Marshal(p1)
	if err != nil {
		panic(err)
	}

	client.Set(context.Background(), id.String(), p1AsJson, time.Hour*24)

	recordAsJson, err := client.Get(context.Background(), "111").Result()

	if err != nil {
		panic(err)
	}
	t.Logf("recordAsJson: %s \n", recordAsJson)

}
