package dev.peerat.backend.routes.admins;

import dev.peerat.backend.routes.EventSSE.GroupMessage;
import dev.peerat.framework.Context;
import dev.peerat.framework.HttpReader;
import dev.peerat.framework.Injection;
import dev.peerat.framework.Locker;
import dev.peerat.framework.RequestType;
import dev.peerat.framework.Route;
import dev.peerat.framework.utils.json.JsonMap;

public class GroupController {
	
	private Locker<GroupMessage> locker;
	
	public GroupController(@Injection("groupMessages") Locker<GroupMessage> locker){
		this.locker = locker;
	}
	
	@Route(path = "^/admin/event/$", type = RequestType.POST ,needLogin = true)
	public void send(Context context, HttpReader reader) throws Exception{
		JsonMap json = reader.readJson();
		if(!json.has("message")){
			context.response(400);
			return;
		}
		
		locker.setValue(new GroupMessage(json.get("group"), json.get("message")));
		context.response(200);
	}

}
