// NKSC1-c8c7ea42327292095dea8150adbebc85-0708f3a4174e426d0d2ad28718b26adb4894e3d58893d8e7340ae63a514fbf41

package license

import (
	"context"
	"log"
	"time"
)

// This tick verifies only local state. LMS renewals follow the signed schedule.
func StartHeartbeat(ctx context.Context, onInvalid func(string)) {
	go func() {
		defer releaseDeviceRuntime()
		ticker := time.NewTicker(time.Minute)
		defer ticker.Stop()
		for {
			select {
			case <-ctx.Done():
				return
			case <-ticker.C:
				if Heartbeat() {
					continue
				}
				stateMu.RLock()
				message, status := VerifyMessage, VerifyStatus
				stateMu.RUnlock()
				log.Printf("[license] Verifikasi dihentikan: %s", status)
				if onInvalid != nil {
					onInvalid(message)
				}
				return
			}
		}
	}()
}
