package web

const (
	SessionNotChanged = 0
	SessionChanged    = 1
	SessionClosed     = 2
)

func NewSessionObject(data map[string]any) *SessionObject {
	s := new(SessionObject)
	if data == nil {
		s.data = make(map[string]any)
	} else {
		s.data = data
	}
	return s
}

type SessionObject struct {
	data   map[string]any
	status int
}

func (s *SessionObject) Set(key string, v any) {
	s.data[key] = v
	if s.status != SessionClosed {
		s.status = SessionChanged
	}
}

func (s *SessionObject) Del(key string) {
	delete(s.data, key)
	if s.status != SessionClosed {
		s.status = SessionChanged
	}
}

func (s *SessionObject) Get(key string) any {
	return s.data[key]
}

func (s *SessionObject) Close() {
	s.status = SessionClosed
}

func (s *SessionObject) Items() map[string]any {
	return s.data
}

func (s *SessionObject) Status() int {
	return s.status
}
