package galog

import (
	"testing"
	"time"
)

var (
	gaLogger    *GALogger
	assetLogger *GALogger
)

// go test -bench . -benchmem
func init() {
	gaLogger, _ = NewGALogger("logs", "20433", "Android_5.0_tyGuest,weixinPay,tyAccount.alipay.0-hall20433.tuyoo.sdktest", LogTypeTrack)
	assetLogger, _ = NewGALogger("logs", "28", "Android_4.827_tyGuest,nearme.nearme.0-hall28.oppo.bydzz", LogTypeAsset)
}

func BenchmarkGaLog(b *testing.B) {
	for i := 0; i < b.N; i++ {
		props := map[string]interface{}{
			"ip_address":       "127.0.0.1",
			"proj_app_id":      "10010",
			"uuid":             "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts":               time.Now().UnixNano(),
			"ip_address1":      "127.0.0.1",
			"proj_app_id1":     "10010",
			"uuid1":            "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts1":              time.Now().UnixNano(),
			"ip_address2":      "127.0.0.1",
			"proj_app_id2":     "10010",
			"uuid2":            "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts2":              time.Now().UnixNano(),
			"ip_address3":      "127.0.0.1",
			"proj_app_id3":     "10010",
			"uuid3":            "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts4":              time.Now().UnixNano(),
			"proj_app_id25":    "10010",
			"uuid21":           "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts21":             time.Now().UnixNano(),
			"ip_address31":     "127.0.0.1",
			"proj_app_id31":    "10010",
			"uuid31":           "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts11":             time.Now().UnixNano(),
			"uuid3111":         "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts4111":           time.Now().UnixNano(),
			"proj_app_id21115": "10010",
			"uuid111":          "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts111":            time.Now().UnixNano(),
			"ip_a11ddress31":   "127.0.0.1",
			"proj1_app_id31":   "10010",
			"uuid131":          "4951d472-2c46-4fe5-9c4f-c35b6fb53f67",
			"ts1111":           time.Now().UnixNano(),
		}
		gaLogger.
			GetEntry("sdk_s_login_succ").
			SetDeviceID("device001").
			SetUserID("10086").
			SetProperties(props).
			Flush()
	}
}

func BenchmarkAssetLog(b *testing.B) {
	for i := 0; i < b.N; i++ {
		asset := make(AssetProperties)
		asset.
			SetAssetID("13101").
			SetAssetName("\u9501\u5b9a").
			SetAssetType("6").
			SetAssetFinal("2").
			SetAssetAssociated("3").
			SetAssetStartTime("0").
			SetAssetTimeLimit("0").
			SetAssetSource("").
			SetKV("uuid", "uuid-v4")

		assetLogger.
			GetEntry("asset_increase").
			SetDeviceID("").
			SetUserID("10086").
			SetProperties(asset).
			Flush()
	}
}
