package eas

import (
	"fmt"
	"strconv"
	"testing"

	"gitlab.alibaba-inc.com/pai_biz_arch/pairec/algorithm/eas/easyrec"
)

func TestEasyrecRequest(t *testing.T) {

	builder := easyrec.NewEasyrecRequestBuilder()

	var id interface{}
	id = 16
	builder.AddItemId(strconv.Itoa(id.(int)))
	builder.AddItemId("1")
	builder.AddItemId("17")
	builder.AddItemId("18")
	builder.AddItemId("67552360")
	builder.AddItemId("7")
	builder.AddItemId("8")
	builder.AddUserFeature("u_action_pv_30d", 1)
	builder.AddUserFeature("u_action_pv_3d", 1)
	builder.AddUserFeature("u_action_pv_7d", 1)
	builder.AddUserFeature("u_active_delta_days", 1)
	builder.AddUserFeature("u_age", 1)
	builder.AddUserFeature("u_browse_uv_3d", 1)

	request := builder.EasyrecRequest()

	req := EasyrecRequest{}
	req.SetUrl("http://1233177768936747.cn-hangzhou.pai-eas.aliyuncs.com/api/predict/milian_cupai")
	req.SetAuth("MGRkZWM0Yzg0ZjllYmNjNmMwMGI1NWU0NTE4ZDIxNzE4N2YyN2M5MA")
	req.SetTimeout(5000)

	response, err := req.Invoke(request)
	if err != nil {
		t.Error(err)
	}
	fmt.Println(response.(*easyrec.PBResponse))
	fmt.Println(fmt.Sprintf("%v", response.(*easyrec.PBResponse)))

	fmt.Println("=========")
	for k, v := range response.(*easyrec.PBResponse).Results {
		fmt.Println(k, v)
		fmt.Println(fmt.Sprintf("%T, %v, %v", k, len(k), k))
	}

	ret, err := easyrecResponseFunc(response)
	if err != nil {
		t.Error(err)
	}

	fmt.Println("=========")
	for _, r := range ret {
		fmt.Println(r.GetScore())
	}

}
