package ru.nsu.ccfit.bogush.chat.message.types;

import ru.nsu.ccfit.bogush.chat.User;
import ru.nsu.ccfit.bogush.chat.message.MessageFactory;
import ru.nsu.ccfit.bogush.chat.message.MessageHandler;

import javax.xml.bind.annotation.*;

@XmlRootElement(name = "command")
@XmlType(factoryClass = MessageFactory.class, factoryMethod = "createEmptyLoginRequest")
@XmlAccessorType(XmlAccessType.NONE)
public class LoginRequest implements Request {
	private User user;
	private String type;

	public LoginRequest(User user, String type) {
		this.user = user;
		this.type = type;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@XmlElement(name = "name")
	public String getUserName() {
		return getUser().getName();
	}

	public void setUserName(String name) {
		if (user == null) {
			setUser(new User(name));
		} else {
			user.setName(name);
		}
	}

	@XmlElement(name = "type")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@XmlAttribute(name = "name")
	public String getRequestName() {
		return "login";
	}

	@Override
	public void handleBy(MessageHandler handler) {
		handler.handle(this);
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + "(" + user + ")";
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		LoginRequest that = (LoginRequest) o;

		return user != null ? user.equals(that.user) : that.user == null;
	}

	@Override
	public int hashCode() {
		return user != null ? user.hashCode() : 0;
	}
}

@@ -460,30 +460,8 @@
 ser;
-%0A%09private String type;
 %0A%0A%09p
@@ -527,32 +527,34 @@
 user;%0A%09%09
-this.type = 
+user.setType(
 type
+)
 ;%0A%09%7D%0A%0A%09p
@@ -942,20 +942,30 @@
 %09return 
-t
+user.getT
 ype
+()
 ;%0A%09%7D%0A%0A%09p
@@ -1004,24 +1004,26 @@
 %7B%0A%09%09
-this.type = 
+user.setType(
 type
+)
 ;%0A%09%7D

Fix type in LoginRequest