package es.uv.garcosda.domain;


import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.security.core.authority.AuthorityUtils;

import com.fasterxml.jackson.annotation.JsonProperty;

@Table(name="MYUSER")
public class MyUser {
	
	@Id
	@JsonProperty("id")
	private Integer id;
	
	@JsonProperty("name")
	private String name;
	
	@JsonProperty("username")
	private String username;
	
	@JsonProperty("password")
	private String password;
	
	@JsonProperty("role")
	private String role;
	
	public MyUser() {}
	
	public MyUser(Integer id, String name, String username, String password, String role) {
		this.id = id;
		this.name = name;
		this.username = username;
		this.password = password;
		this.role = role;
	}
	
	public MyUser(String name, String username, String password, String role) {
		this.name = name;
		this.username = username;
		this.password = password;
		this.role = role;
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getRole() {
		return role;
	}
	public void setRole(String roles) {
		this.role = roles;
	}
	public org.springframework.security.core.userdetails.User toAuthUser() {
    	return new org.springframework.security.core.userdetails.User(this.username, this.password, 
    																  AuthorityUtils.createAuthorityList(this.getRole()));
    }
}
