package yinbaoapi

import (
	"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("1131812849010800342", "1F42E107A9A6B6B91B064B0B9D1147A1") //总店
	api.SetCookie(".POSPALAUTH30220", "01022774A1129E1DD808FE27DC6574A61DD808000833003900330036003000380037003A0000012F00FF70654DF44FCE339A45E682CD9ECC45C91C7A11AA")
}

func TestAddProductInfo(t *testing.T) {
	var (
		stock = 5.1
	)
	result, err := api.AddProductInfo(&ProductInfoParam{
		ProductInfo: &ProductInfo{
			Name:        "测试商品",
			Barcode:     "12131",
			BuyPrice:    &stock,
			SellPrice:   &stock,
			Stock:       &stock,
			SupplierUID: 123,
			CategoryUID: 1585290800642661192,
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestUpdateProductInfo(t *testing.T) {
	var (
		sellPrice = float64(-1)
	)
	err := api.UpdateProductInfo(
		&ProductInfo{
			UID:       285305464077105187,
			SellPrice: &sellPrice,
		},
	)
	if err != nil {
		t.Fatal(err)
	}
}

func TestQueryProductByBarcode(t *testing.T) {
	result, err := api.QueryProductByBarcode("0012113")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestQueryProductByBarcodes(t *testing.T) {
	result, err := api.QueryProductByBarcodes([]string{
		"0010724",
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestQueryProductImagesByBarcode(t *testing.T) {
	result, err := api.QueryProductImagesByBarcode("22510")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestQueryProductPages(t *testing.T) {
	result, err := api.QueryProductPages(&PostBackParameter{
		ParameterType:  "LAST_RESULT_MAX_ID",
		ParameterValue: "13672479",
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}
