package document

import protocol "wellquite.org/edist/protocol/go"

type frame struct {
	eventNumber  uint64
	message      *protocol.Message
	isCheckpoint bool
	undoCount    uint64
	redoCount    uint64

	previous *frame
	next     *frame
}

type frames []*frame
type frameStack struct {
	frames map[int]*frame
}

func newFrameStack() *frameStack {
	return &frameStack{
		frames: make(map[int]*frame),
	}
}

func (self *frameStack) ensureMessagelessFrame(index int) *frame {
	result, found := self.frames[index]
	if !found || result.message != nil {
		result = &frame{}
		self.frames[index] = result
	}
	return result
}

func (self *frameStack) hasMessagelessFrames() bool {
	for _, frame := range self.frames {
		if frame.message == nil {
			return true
		}
	}
	return false
}
