package mtunionapi

import (
	"fmt"
	"strings"
	"testing"

	"git.rosy.net.cn/baseapi"
	"git.rosy.net.cn/baseapi/utils"
	"go.uber.org/zap"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)

	api = New("b6481f92b47918cd6e42e7ea4fae6084", "84d390777ddf691ff092e744ba26bfdd")
	api.SetCookieWithStr(`
		uuid=e8034a4d222c4b51b81c.1574126611.1.0.0; _ga=GA1.2.827950563.1574128001; _lxsdk_cuid=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; _lxsdk=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; t_lxid=1719bfe9d5e30-0cf08957b60ff-3d375b01-15f900-1719bfe9d5fc8-tid; e_u_id_3299326472=e5ae16afe444349d24af7d33b66620a1; mtcdn=K; u=74293087; n=%E6%9A%96%E6%B4%8B%E6%B4%8B780; lt=-MCY1pDT4PeX0lQfwwtk0fopfp4AAAAASg0AAGrpsRgMgRyfrItJI72VozmV508m0TpAAxLhJPZqKBxw3xeClF25NKbWolIKKQIB-g; mt_c_token=-MCY1pDT4PeX0lQfwwtk0fopfp4AAAAASg0AAGrpsRgMgRyfrItJI72VozmV508m0TpAAxLhJPZqKBxw3xeClF25NKbWolIKKQIB-g; token=-MCY1pDT4PeX0lQfwwtk0fopfp4AAAAASg0AAGrpsRgMgRyfrItJI72VozmV508m0TpAAxLhJPZqKBxw3xeClF25NKbWolIKKQIB-g; lsu=

	`)
}

func TestMiniCode(t *testing.T) {
	result, err := api.MiniCode(2, strings.ToLower("9999999999999"))
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestGenerateLink(t *testing.T) {
	result, err := api.GenerateLink(2, 1, strings.ToLower("9999999999999"))
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestActivityList(t *testing.T) {
	result, err := api.ActivityList(1, 10, 0)
	if err != nil {
		t.Fatal(err)
	}
	for _, v := range result {
		fmt.Println(utils.Str2Time(v.DateBound[:strings.LastIndex(v.DateBound, "至")-1]))
		fmt.Println(utils.Str2Time(v.DateBound[strings.LastIndex(v.DateBound, "至")+4:]))
	}
	t.Log(utils.Format4Output(result, false))
}
