package router

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

	"gogs.daxia.dev/huanan/pkg.daxia.dev/encrypt"
	"nn.daxia.dev/model"
)

func Test_parseMsg(t *testing.T) {
	type args struct {
		message []byte
		aesKey  []byte
	}
	tests := []struct {
		name    string
		args    args
		want    *BaseReq
		wantErr bool
	}{
		{
			name: "d1",
			args: args{
				message: []byte("QkkxrEKXU85pltI9L89KUPjtUFgGV0ay3kVNWrjlCKdYdKI4ekx7HcyIvZ/Bzwd6gPpZiZbyuwkJUI2dUX8ok1+/yqiX9Ch09KkzsZf4I+Y="),
				aesKey:  model.AESKey,
			},
			want: &BaseReq{
				Type: "connect",
			},
			wantErr: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := parseMsg(tt.args.message, tt.args.aesKey)
			if (err != nil) != tt.wantErr {
				t.Errorf("parseMsg() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("parseMsg() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestX(t *testing.T) {
	hexStr := "516b6b7872454b58553835706c7449394c38394b55444855424462304575794b48692b72554f50396c66705a78312f7749732b526e7866645a2b6858326e524d596d70437a4b507951682b514d333867506a5a4f45333448544d33324c34534341387a4b6369334f796d553646484977486f644462736459716c2b4a52672b35"
	decBody, err := hex.DecodeString(hexStr)
	if err != nil {
		t.Fatal(err)
	}

	decBody, err = encrypt.AesDecrypt(decBody, model.AESKey)
	if err != nil {
		t.Fatal(err)
	}

	decBodyStr := string(decBody)
	fmt.Println(decBodyStr)
}
