package main // A licence's room (design 39 bus-and-switch §25, §48, C4): 100 less its weekly percentage in its latest reading, the // session window taking no part (the vendor retired the session limit), known only for a subscription read successfully within usage_stale_minutes, whose refresh has not // failed failures_to_notify times in a row and whose refresh token has not expired. An API key's room is never known, // so it is never a target. import ( "time" . "claude-licence-manager/internal/licences" ) // Room is a licence's room at now, and whether it is known. func Room(l Licence, now time.Time, s Settings) (float64, bool) { if l.Kind != "subscription" || l.Usage == nil || l.Usage.WeeklyPct == nil { return 0, false } read, err := time.Parse(time.RFC3339Nano, l.Usage.ReadAt) if err != nil || now.Sub(read) > s.UsageStale { return 0, false } if l.Failures >= s.FailuresToNotify || (l.RefreshExpiresAt != 0 && l.RefreshExpiresAt <= now.UnixMilli()) { return 0, false } return 100 - *l.Usage.WeeklyPct, true }