/*
 * 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 plate.wellmann.shop.persistence;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

/**
 *
 * @author Patrick
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Costumer.findByEmail",
            query = "SELECT c FROM Costumer c WHERE c.email = :email"),
    @NamedQuery(name = "Costumer.findByID",
            query = "SELECT c FROM Costumer c WHERE c.id = :id")
})
public class Costumer extends AbstractEntity {

    public static Costumer nullCostumer = new Costumer();
    
    @ManyToOne(cascade = CascadeType.ALL)
    private UserDomain userDomain;
    
    @Column(name="Email", unique=true, nullable=false)
    private String email;
    
    @OneToOne(cascade = CascadeType.ALL)
    private Password password;
    
    @OneToOne(cascade = CascadeType.ALL)
    private Salt salt;
    
    @Column(name="Kunde")
    private String kunde;
    
    @Column(name="Kunde2")
    private String kunde2;
    
    @Column(name="Ansprechpartner")
    private String contact;
    
    @Column(name="Straße")
    private String street;
    
    @Column(name="Ort")
    private String city;
    
    @Column(name="Telefon")
    private String telefon;
    
    @Column(name="Mobil")
    private String mobile;
    
    @Column(name="Anrede")
    private String call;
    
    @Column(name="Liefername")
    private String deliveryName;
    
    @Column(name="Lieferansprechpartner")
    private String deliveryContakt;
    
    @Column(name="Lieferort")
    private String deliveryCity;
    
    @Column(name="Lieferstraße")
    private String deliveryStreet;
    
    //Besser als enum
    @Column(name="Zahlungsbedingungen")
    private String paymentConditions;

    public Costumer(String email, byte[] password, Salt salt) {
        this.email = email;
        this.password = new Password(this, password);
        this.salt = salt;
        this.userDomain = new UserDomain(email.substring(email.indexOf("@") + 1), this);
    }
    
    public Costumer(String email, byte[] password, Salt salt, String domain) {
        this.email = email;
        this.password = new Password(this, password);
        this.salt = salt;
        this.userDomain = new UserDomain(domain, this);
    }
    
    public Costumer(String email, byte[] password, Salt salt, UserDomain domain){
        this.email = email;
        this.password = new Password(this, password);
        this.salt = salt;
        this.userDomain = domain;
    }

    private Costumer() {
    }

    public Password getPassword() {
        return password;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public static Costumer getNullCostumer() {
        return nullCostumer;
    }

    public static void setNullCostumer(Costumer nullCostumer) {
        Costumer.nullCostumer = nullCostumer;
    }

    public UserDomain getDomain() {
        return userDomain;
    }

    public void setDomain(UserDomain domain) {
        this.userDomain = domain;
    }

    public String getKunde() {
        return kunde;
    }

    public void setKunde(String kunde) {
        this.kunde = kunde;
    }

    public String getKunde2() {
        return kunde2;
    }

    public void setKunde2(String kunde2) {
        this.kunde2 = kunde2;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getTelefon() {
        return telefon;
    }

    public void setTelefon(String telefon) {
        this.telefon = telefon;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getCall() {
        return call;
    }

    public void setCall(String call) {
        this.call = call;
    }

    public String getDeliveryName() {
        return deliveryName;
    }

    public void setDeliveryName(String deliveryName) {
        this.deliveryName = deliveryName;
    }

    public String getDeliveryContakt() {
        return deliveryContakt;
    }

    public void setDeliveryContakt(String deliveryContakt) {
        this.deliveryContakt = deliveryContakt;
    }

    public String getDeliveryCity() {
        return deliveryCity;
    }

    public void setDeliveryCity(String deliveryCity) {
        this.deliveryCity = deliveryCity;
    }

    public String getDeliveryStreet() {
        return deliveryStreet;
    }

    public void setDeliveryStreet(String deliveryStreet) {
        this.deliveryStreet = deliveryStreet;
    }

    public String getPaymentConditions() {
        return paymentConditions;
    }

    public void setPaymentConditions(String paymentConditions) {
        this.paymentConditions = paymentConditions;
    }

    public Salt getSalt() {
        return salt;
    }

    public void setSalt(Salt salt) {
        this.salt = salt;
    }
}
