package com.palmnest.model.estateserve;

import com.palmnest.application.Constants;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

@Entity
@Table(name = "tb_vir_account")
public class VirtualAccount implements Serializable, UserDetails {

	/**
	 *
	 */
	private static final long serialVersionUID = 1179669277518578227L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", unique = true, nullable = false)
	private Long   id;
	private int    virId;
	private String virAccount;
	private String password;
	private String creator;
	private Date   createTime;
	private String modifier;
	private Date   modifyTime;
	private String isEnable;
	private String orgId;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public int getVirId() {
		return virId;
	}

	public void setVirId(int virId) {
		this.virId = virId;
	}

	public String getVirAccount() {
		return virAccount;
	}

	public void setVirAccount(String virAccount) {
		this.virAccount = virAccount;
	}

	@JsonIgnore
	@Transient
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> roleList = new ArrayList<GrantedAuthority>();
		GrantedAuthority authority1 = new SimpleGrantedAuthority(Constants.ADMIN_ROLE);
		GrantedAuthority authority2 = new SimpleGrantedAuthority(Constants.USER_ROLE);
		roleList.add(authority1);
		roleList.add(authority2);
		return roleList;
	}

	public String getPassword() {
		return password;
	}

	@JsonIgnore
	@Transient
	@Override
	public String getUsername() {
		return virAccount;
	}

	@JsonIgnore
	@Transient
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@JsonIgnore
	@Transient
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@JsonIgnore
	@Transient
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@JsonIgnore
	@Transient
	@Override
	public boolean isEnabled() {
		return true;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}


}
