package galog

var (
	defaultLib = map[string]string{"lib_type": "go", "lib_version": "v1.0.0"}
)

type EntryBean struct {
	// ProjectID 独立项目ID
	ProjectID string `json:"project_id"`
	// LogType 日志类型 默认是track
	LogType LogType `json:"type"`
	// Event 事件ID
	Event string `json:"event"`
	// EventTime 毫秒级时间
	EventTime int64 `json:"event_time"`
	// DeviceID 设备ID
	DeviceID string `json:"device_id"`
	// UserID 用户ID
	UserID string `json:"user_id"`
	// ClientID clientID
	ClientID string `json:"client_id"`
	// Properties 重要额外字段
	Properties map[string]interface{} `json:"properties"`
	// Lib 代码库
	Lib map[string]string `json:"lib"`
}

type Entry struct {
	logger *GALogger
	bean   *EntryBean
}

func (e *Entry) SetUserID(uid string) *Entry {
	if uid == "" {
		uid = "0"
	}
	e.bean.UserID = uid
	return e
}

func (e *Entry) SetDeviceID(did string) *Entry {
	e.bean.DeviceID = did
	return e
}

func (e *Entry) SetLib(lib map[string]string) *Entry {
	e.bean.Lib = lib
	return e
}

func (e *Entry) SetClientID(cid string) *Entry {
	e.bean.ClientID = cid
	return e
}

func (e *Entry) SetProperties(props map[string]interface{}) *Entry {
	e.bean.Properties = props
	return e
}

// Flush 日志写入
func (e *Entry) Flush() {
	defer e.logger.putEntry(e)
	e.logger.biz(e.bean)
}

type AssetProperties map[string]interface{}

// SetAssetID 资产id
func (ap AssetProperties) SetAssetID(assetID string) AssetProperties {
	ap["proj_asset_id"] = assetID
	return ap
}

// SetAssetName 资产名称
func (ap AssetProperties) SetAssetName(assetName string) AssetProperties {
	ap["proj_asset_name"] = assetName
	return ap
}

// SetAssetType 资产付费类型
func (ap AssetProperties) SetAssetType(assetType string) AssetProperties {
	ap["proj_asset_type"] = assetType
	return ap
}

// SetAssetValue 资产变化数量
func (ap AssetProperties) SetAssetValue(assetValue string) AssetProperties {
	ap["proj_asset_value"] = assetValue
	return ap
}

// SetAssetFinal 资产变化后的剩余数量
func (ap AssetProperties) SetAssetFinal(assetFinal string) AssetProperties {
	ap["proj_asset_final"] = assetFinal
	return ap
}

// SetAssetTimeLimit 持续性资产持续时间
func (ap AssetProperties) SetAssetTimeLimit(assetTimeLimit string) AssetProperties {
	ap["proj_asset_time_limit"] = assetTimeLimit
	return ap
}

// SetAssetStartTime 持续性资产生效时间
func (ap AssetProperties) SetAssetStartTime(assetStartTime string) AssetProperties {
	ap["proj_asset_start_time"] = assetStartTime
	return ap
}

// SetAssetSource 变化的原因
func (ap AssetProperties) SetAssetSource(assetSource string) AssetProperties {
	ap["proj_asset_source"] = assetSource
	return ap
}

// SetAssetAssociated 变化关联资产
func (ap AssetProperties) SetAssetAssociated(assetAssociated string) AssetProperties {
	ap["proj_asset_associated"] = assetAssociated
	return ap
}

// SetTuyooOrderID SDK订单号
func (ap AssetProperties) SetTuyooOrderID(tuyooOrderID string) AssetProperties {
	ap["proj_tuyoo_order_id"] = tuyooOrderID
	return ap
}

// SetOrderID 游戏服订单号
func (ap AssetProperties) SetOrderID(assetOrderID string) AssetProperties {
	ap["proj_order_id"] = assetOrderID
	return ap
}

// SetKV 设置自定义字段必须通知到数据组，否则打点失败
func (ap AssetProperties) SetKV(k, v string) AssetProperties {
	ap[k] = v
	return ap
}
