package com.acme.model.domain.sc.entity;


import com.acme.model.domain.ejf.entity.User;
import com.acme.structure.BaseEntityListener;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity(name = "CustomerUser")
@Table(name = "CUSTOMERUSERS")
@DiscriminatorValue("CustomerUser")
@PrimaryKeyJoinColumn(name = "USERID", referencedColumnName = "ID")
@EntityListeners( { BaseEntityListener.class })
public class CustomerUser extends User
{
    private Collection<CustomerDeliveryAddress> deliveryAddresses;
    private Collection<CustomerContact> contacts;
    private Date dateOfBirth;
    private int maritalStatus;
    private int gender;

    public CustomerUser()
    {
        entityName = "CustomerUser";
        setUserType(this.getEntityName());
        setPassive(true);
        deliveryAddresses = new ArrayList<CustomerDeliveryAddress>();
    }

    public void setDeliveryAddresses(Collection<CustomerDeliveryAddress> deliveryAddresses)
    {
        this.deliveryAddresses = deliveryAddresses;
    }

    @OneToMany(targetEntity = CustomerDeliveryAddress.class, fetch = (FetchType.EAGER), cascade = { CascadeType.ALL })
    @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "CUSTOMERUSERID")
    public Collection<CustomerDeliveryAddress> getDeliveryAddresses()
    {
        return deliveryAddresses;
    }

    public void setDateOfBirth(Date dateOfBirth)
    {
        this.dateOfBirth = dateOfBirth;
    }

    @Column(name = "DATEOFBIRTH")
    @Temporal(TemporalType.DATE)
    public Date getDateOfBirth()
    {
        return dateOfBirth;
    }

    public void setContacts(Collection<CustomerContact> contacts)
    {
        this.contacts = contacts;
    }
    
    @OneToMany(targetEntity = CustomerContact.class, fetch = (FetchType.EAGER), cascade = { CascadeType.ALL })
    @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "CUSTOMERUSERID")
    public Collection<CustomerContact> getContacts()
    {
        return contacts;
    }

    public void setMaritalStatus(int maritalStatus)
    {
        this.maritalStatus = maritalStatus;
    }

    @Column(name = "MARITALSTATUS")
    public int getMaritalStatus()
    {
        return maritalStatus;
    }

    public void setGender(int gender)
    {
        this.gender = gender;
    }

    @Column(name = "GENDER")
    public int getGender()
    {
        return gender;
    }
}
