package main

import (
	"cicv-data-closedloop/pjisuv_msgs"
	"cicv-data-closedloop/pjisuv_param"
	"fmt"
	"time"
)

var (
	StartTime int64
	IsStopped bool
)

func Topic() string {
	return "/pj_vehicle_fdb_pub"
}

// Label todo 禁止存在下划线_
func Label() string {
	return "AuLongStop"
}

func Rule(data *pjisuv_msgs.PerceptionLocalization, param pjisuv_param.PjisuvParam) string {
	if param.AutomodeOfPjVehicleFdbPub == 1 {
		if data.VelocityX < 0.5 {
			// 如果之前没有记录开始时间，记录当前时间
			if StartTime == 0 {
				StartTime = time.Now().Unix()
			}
			// 判断是否持续超过 50s
			if time.Now().Unix()-StartTime > 50 {
				if !IsStopped {
					event_label := "AuLongStop"
					fmt.Println(event_label)
					IsStopped = true
					return "AuLongStop"
				}
			}
		} else {
			// 如果速度大于 0.1，重置开始时间和停止标志
			StartTime = 0
			IsStopped = false
		}
	} else {
		StartTime = 0
		IsStopped = false
	}
	return ""
}
