/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.person;

import java.util.Arrays;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

import model.AbstractEntity;

/**
 *
 * @author Patrick
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Password.findByPassword",
            query = "SELECT p FROM Password p WHERE p.password = :password"),
    @NamedQuery(name = "Password.findByCostumerID",
            query = "SELECT p FROM Password p WHERE p.person = :person")
})
public class Password extends AbstractEntity {
	private static final long serialVersionUID = -1924150926160449302L;

	@OneToOne
    private Person person;
    
    @Column(name="password")
    private byte[] password;
    
    public Password() {
	}
    
    public Password (Person person, byte[] password) {
        this.person = person;
        this.password = password;
    }
    
    public Person getPerson() {
        return person;
    }

    public byte[] getPassword() {
        return password;
    }
    
    public void setPassowrd(byte[] password){
        this.password = password;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 79 * hash + Objects.hashCode(this.person);
        hash = 79 * hash + Arrays.hashCode(this.password);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Password other = (Password) obj;
        if (!Objects.equals(this.person, other.person)) {
            return false;
        }
        if (!Arrays.equals(this.password, other.password)) {
            return false;
        }
        return true;
    }
}
