import Foundation

struct Times {
    struct Item {
        private var current: TimeInterval
        private let max: TimeInterval
        
        init(_ max: TimeInterval) {
            self.max = max
            current = max
        }
        
        mutating func timeout(_ with: TimeInterval) -> Bool {
            current -= with
            guard current <= 0 else { return false }
            current = max
            return true
        }
    }
    
    var follow = Item(0.02)
    var move = Item(0.05)
    var foes = Item(0.025)
    var radar = Item(0.1)
    var seconds = Item(1)
    private var last = TimeInterval()
    
    mutating func delta(_ time: TimeInterval) -> TimeInterval {
        guard last > 0 else {
            last = time
            return 0
        }
        let delta = time - last
        last = time
        return delta
    }
}
