package mtwmapi

import (
	"testing"
	"time"

	"git.rosy.net.cn/baseapi/utils"
)

func TestFullDiscountBatchSave(t *testing.T) {
	result, err := api.FullDiscountBatchSave(testPoiCode, &FullDiscountActInfo{
		// ActIDs:    "12345678",
		ActName:   "测试活动0402",
		StartTime: time.Now().Unix(),
		EndTime:   time.Now().Add(24 * time.Hour).Unix(),
		ActType:   ActTypeStoreFullDiscount,
	}, []*FullDiscountActDetail{
		&FullDiscountActDetail{
			OriginalPrice: 10000,
			ActPrice:      1,
		},
	}, /*[]*ActSkuInfo{
			&ActSkuInfo{
				AppFoodCode: "30902",
				DayLimit:    1,
			},
		}*/nil)
	if err != nil {
		t.Fatal(err)
	}
	// 30902
	t.Log(result)
}

func TestFullDiscountList(t *testing.T) {
	result, err := api.FullDiscountList(testPoiCode, ActTypeStoreFullDiscount)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestFullDiscountFoodsList(t *testing.T) {
	result, err := api.FullDiscountFoodsList(testPoiCode, "497726932")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestFulllDiscountShippingFeeBatchSave(t *testing.T) {
	err := api.FulllDiscountShippingFeeBatchSave(testPoiCode, []*ShippingFeeActData{&ShippingFeeActData{}})
	if err != nil {
		t.Fatal(err)
	}
}

func TestFulllDiscountShippingFeeList(t *testing.T) {
	result, err := api.FulllDiscountShippingFeeList(testPoiCode)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestRetailDiscountBatchSave(t *testing.T) {
	result, _, err := api.RetailDiscountBatchSave2("7845503", 0, []*RetailDiscountActData{
		&RetailDiscountActData{
			AppFoodCode:         "6039423",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "6043140",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "31765",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "31239",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "6042282",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "31901",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "6043147",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "30645",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
		&RetailDiscountActData{
			AppFoodCode:         "30729",
			StartTime:           time.Now().Unix(),
			EndTime:             time.Now().Add(24 * time.Hour).Unix(),
			OrderLimit:          1,
			DayLimit:            -1,
			SettingType:         SettingTypeAsDiscount,
			DiscountCoefficient: 9.5,
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestRetailDiscountList(t *testing.T) {
	result, err := api.RetailDiscountList("8040309", RetailActTypeDirectDown)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestRetailDiscountDelete(t *testing.T) {
	err := api.RetailDiscountDelete(testPoiCode, RetailActTypeDirectDown, []string{"329187452"})
	if err != nil {
		t.Fatal(err)
	}
}

func TestInStoreCouponList(t *testing.T) {
	result, err := api.InStoreCouponList(testPoiCode, 1, 100)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}

func TestParseErr4RetailDiscountDelete(t *testing.T) {
	errStr := `
	{"error_list":[{"act_id":1053302130,"error_msg":"活动ID不存在"},{"act_id":1053302127,"error_msg":"活动ID不存在"},{"act_id":1053302128,"error_msg":"活动ID不存在"},{"act_id":1053302129,"error_msg":"活动ID不存在"},{"act_id":1053302135,"error_msg":"活动ID不存在"},{"act_id":1053302132,"error_msg":"活动ID不存在"},{"act_id":1053302123,"error_msg":"活动ID不存在"},{"act_id":1053302125,"error_msg":"活动ID不存在"},{"act_id":1053302124,"error_msg":"活动ID不存在"},{"act_id":1053302133,"error_msg":"活动ID不存在"},{"act_id":1053302126,"error_msg":"活动ID不存在"},{"act_id":1053302134,"error_msg":"活动ID不存在"},{"act_id":1053302131,"error_msg":"活动ID不存在"}]}

	`
	errExt := utils.NewErrorCode(errStr, "")
	failedList := ParseErr4RetailDiscountDelete(errExt)
	t.Log(utils.Format4Output(failedList, false))
}

func TestGetByAppPoiCodeAndType(t *testing.T) {
	result, err := api.GetByAppPoiCodeAndType("10305601", 1, 1)
	if err != nil {
		t.Fatal(err)
	}
	t.Log(utils.Format4Output(result, false))
}
