package enterprise

import (
	"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
	"git.rosy.net.cn/baseapi/utils"
	"git.rosy.net.cn/jx-callback/business/jxutils"
	"git.rosy.net.cn/jx-callback/business/model"
	"git.rosy.net.cn/jx-callback/globals"
	"testing"
)

func TestOOO(t *testing.T) {
	product := map[string]interface{}{
		"apply_quantity":           1,
		"apply_refund_time":        1711447475000,
		"apply_refund_user_amount": 143,
		"commodity_type":           2,
		"custom_sku_id":            "25381",
		"custom_sku_spec_id":       "",
		"discount_detail": map[string]interface{}{
			"agent_discount_amount":    0,
			"discount_total_amount":    577,
			"merchant_discount_amount": 563,
			"platform_discount_amount": 14,
			"total_price":              720,
			"user_discount_amount":     0,
		},
		"free_gift":                          false,
		"fund_calculate_type":                0,
		"gift_related_sub_biz_order_id_list": nil,
		"is_combine":                         false,
		"last_refund_status":                 0,
		"platform_sku_id":                    16319366072214214,
		"refund_order_id":                    2403269635888396215,
		"refund_quantity":                    1,
		"refund_status":                      50,
		"refund_user_amount":                 143,
		"refund_weight":                      350,
		"sku_name":                           "【尽享好价】西红柿 番茄约300~350g/组",
		"sku_spec_id":                        "null",
		"sub_biz_order_id":                   "4006435770425226215",
		"upc":                                "upc-25381",
		"virtual_type":                       "0",
	}
	skuList := aa(product)
	globals.SugarLogger.Debugf("=====skulist := %s", utils.Format4Output(skuList, false))

}

func aa(product map[string]interface{}) (skuList []*model.OrderSku) {
	skuList = make([]*model.OrderSku, 0, 0)
	if product["virtual_type"] == ebaiapi.OrderVirtualType {
		skuName := product["sku_name"].(string)
		_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
		number := int(utils.MustInterface2Int64(product["apply_quantity"]))
		sku := &model.OrderSku{
			VendorOrderID: "1",
			VendorID:      model.VendorIDEBAI,
			Count:         number,
			SkuID:         int(utils.Str2Int64WithDefault(utils.Interface2String(product[ebaiapi.KeyCustomSkuID]), 0)),
			VendorSkuID:   utils.Int2Str(product["platform_sku_id"].(int)),
			SkuName:       skuName,
			Weight:        int(utils.Interface2Int64WithDefault(product["refund_weight"], 0)) / number, // 退单这里的total_weight有BUG，这里的total_weight还是没有退单时的值
			VendorPrice:   utils.MustInterface2Int64(product["refund_user_amount"]),
		}
		//sku.SalePrice, _, sku.StoreSubName = getSkuSalePrice(product)
		sku.SalePrice = utils.Interface2Int64WithDefault(product["discount_detail"].(map[string]interface{})["total_price"], 0)
		if sku.Weight == 0 {
			sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) // 订单信息里没有重量，只有名字里尝试找
		}
		skuList = append(skuList, sku)
	}
	return skuList
}
