package rest_websocket

import (
	"git.ali33.ru/fcg-xvii/rest"
)

type Answer struct {
	*Message
	err    rest.IErrorArgs
	socket *WebSocket
}

func (s *Answer) IsError() bool {
	return s.err != nil
}

func (s *Answer) KeySet(key string, val any) {
	s.data[key] = val
}

func (s *Answer) FileSet(name string, file rest.IReadCloserLen) {
	if !s.IsError() {
		s.files[name] = file
	}
}

func (s *Answer) Send(any) rest.IErrorArgs {
	if s.IsError() {
		s.data = s.err.Map()
		s.data["error"] = true
		s.Close()
		s.files = nil
	}
	return s.socket.sendMessage(s.Message)
}
