package jxprintapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi"
	"go.uber.org/zap"
	"testing"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

//120220915001594

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

	api = New("1000", "rfBd56ti2SMtYvSg")
}

func TestAddPrinter(t *testing.T) {
	err := api.AddPrinter([]*AddPrinterParam{
		&AddPrinterParam{
			PrintNo: "120220915001594",
			Name:    "test1",
		},
	})
	if err != nil {
		t.Fatalf("PrintMsg return error:%v", err)
	}
	//baseapi.SugarLogger.Debug(result)
}

func TestDelPrinter(t *testing.T) {
	err := api.DelPrinter([]string{"120220915001594"}, "")
	if err != nil {
		t.Fatalf("PrintMsg return error:%v", err)
	}
	//baseapi.SugarLogger.Debug(result)
}

func TestUpdatePrinter(t *testing.T) {
	err := api.UpdatePrinter(&UpdatePrinterParam{
		PrintNo: "120220915001594",
	})
	if err != nil {
		t.Fatalf("PrintMsg return error:%v", err)
	}
	//baseapi.SugarLogger.Debug(result)
}

func TestDelPrinterSeq(t *testing.T) {
	err := api.DelPrinterSeq("120220915001594")
	if err != nil {
		t.Fatal(err)
	}
	//t.Log(utils.Format4Output(result, false))
}

func TestGetPrintMsg(t *testing.T) {
	result, err := api.GetPrintMsg("120220915001594")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(result)
}

func TestGetPrinterStatus(t *testing.T) {
	result, err := api.GetPrinterStatus("120220915001330")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(result)
}

// 20210615000012
func TestDoPrint(t *testing.T) {
	result, err := api.DoPrint("120220915001330", `{
    "allSkuCount": "11",
    "allSkuTypeCount": "11",
    "appId": "1000",
    "businessType": "1",
    "buyerComment": "【如遇缺货】：缺货时电话与我沟通 收货人隐私号 18428944043,9133，手机号 157****5586",
    "consigneeAddress": "鹭岛国际4期-6栋-1单元 (6栋一单元1711)@#四川省成都市武侯区红牌楼街道鹭岛国际4期",
    "consigneeMobile": "18428944043,9133",
    "consigneeName": "测试订单无需拣货",
    "eBailCode": "",
    "officialName": "测试订单无需拣货",
    "orderNo": "3401827041718147024",
    "orderStatus": "10",
    "payOrderTime": "2025-10-20 18:46:58",
    "qrcOrder": "3401827041718147024",
    "skuList": "[{\"skuName\":\"【新鲜】精猪瘦肉片约150g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥7.90\",\"totalCountPrice\":\"￥7.90\",\"upc\":\"\"},{\"skuName\":\"（火锅）海带结约150g/袋\",\"skuCount\":\"X1\",\"salePrice\":\"￥4.80\",\"totalCountPrice\":\"￥4.80\",\"upc\":\"\"},{\"skuName\":\"【新鲜】西红柿 番茄约500g/份(约450-500g左右)\",\"skuCount\":\"X1\",\"salePrice\":\"￥5.90\",\"totalCountPrice\":\"￥5.90\",\"upc\":\"\"},{\"skuName\":\"【新鲜】嫩豆腐1块约250g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥2.30\",\"totalCountPrice\":\"￥2.30\",\"upc\":\"\"},{\"skuName\":\"奶油生菜约500g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥5.90\",\"totalCountPrice\":\"￥5.90\",\"upc\":\"\"},{\"skuName\":\"【新鲜】平菇 蘑菇约150g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥3.60\",\"totalCountPrice\":\"￥3.60\",\"upc\":\"\"},{\"skuName\":\"【新鲜】鲜香菇 蘑菇约150g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥4.10\",\"totalCountPrice\":\"￥4.10\",\"upc\":\"\"},{\"skuName\":\"【火锅食材】现切莴笋条 火锅配菜约250g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥4.10\",\"totalCountPrice\":\"￥4.10\",\"upc\":\"\"},{\"skuName\":\"【火锅伴侣】火锅套餐 素菜组合约1kg/组\",\"skuCount\":\"X1\",\"salePrice\":\"￥14.30\",\"totalCountPrice\":\"￥14.30\",\"upc\":\"\"},{\"skuName\":\"【火锅伴侣】火锅丸子组合（随机2-4种）约250g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥8.30\",\"totalCountPrice\":\"￥8.30\",\"upc\":\"\"},{\"skuName\":\"【火锅侠】牛肉卷约100g/份\",\"skuCount\":\"X1\",\"salePrice\":\"￥11.70\",\"totalCountPrice\":\"￥11.70\",\"upc\":\"\"}]",
    "storeName": "京西菜市（武侯大道店）",
    "storeTel": "18140114975",
    "trySendTime": "2025-10-20 19:27:01",
    "userPayMoney": "￥74.33",
    "vendorID": "1",
    "vendorName": "美团外卖",
    "vendorOrderNo": "7"
}`, 17)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(result)
}

func TestGetPrintList(t *testing.T) {
	list, count, err := api.GetPrintList("", "", 0, 0, 0, 10)
	fmt.Println(list)
	fmt.Println(count)
	fmt.Println(err)
}
