/*******************************************************************************
 * Copyright (c) 1998, 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     06/20/2008-1.0 Guy Pelletier 
 *       - 232975: Failure when attribute type is generic
 *     01/28/2009-2.0 Guy Pelletier 
 *       - 248293: JPA 2.0 Element Collections (part 1)   
 *     02/06/2009-2.0 Guy Pelletier 
 *       - 248293: JPA 2.0 Element Collections (part 2)
 *     03/27/2009-2.0 Guy Pelletier 
 *       - 241413: JPA 2.0 Add EclipseLink support for Map type attributes
 *     04/03/2009-2.0 Guy Pelletier
 *       - 241413: JPA 2.0 Add EclipseLink support for Map type attributes
 ******************************************************************************/
package org.eclipse.persistence.testing.models.jpa.inherited;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.AssociationOverride;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyClass;
import javax.persistence.MapKeyColumn;
import javax.persistence.MapKeyTemporal;

import static javax.persistence.FetchType.EAGER;
import static javax.persistence.TemporalType.DATE;

@Entity(name="EXPERT_CONSUMER")
@DiscriminatorValue(value="EBC")
@AttributeOverrides({
    @AttributeOverride(name="records.date", column=@Column(name="RECORD_DATE")),
    @AttributeOverride(name="records.description", column=@Column(name="DESCRIPTION")),
    @AttributeOverride(name="records.venue.attendance", column=@Column(name="WITNESSES"))
})
@AssociationOverride(name="records.location", joinColumns=@JoinColumn(name="LOCATION_ID", referencedColumnName="ID"))
public class ExpertBeerConsumer extends RatedBeerConsumer<String, String, String> {
    private Map<Date, String> quotes;
    //private Collection<byte[]> audio;
    private Map<Birthday, String> celebrations;
    
    public ExpertBeerConsumer() {
        super();
        //audio = new ArrayList<byte[]>();
        quotes = new HashMap<Date, String>();
        celebrations = new HashMap<Birthday, String>();
    }   
    
    public void addCelebration(Birthday birthday, String details) {
        celebrations.put(birthday, details);
    }
    
    // Commenting out this mapping until bug 272298 is resolved.
    //@BasicCollection
    //@Lob
    //public Collection<byte[]> getAudio() {
        //return audio;
    //}
    
    @ElementCollection(fetch=EAGER)
    @MapKeyClass(Birthday.class)
    @AttributeOverrides({
      @AttributeOverride(name="key.day", column=@Column(name="BIRTH_DAY")),
      @AttributeOverride(name="key.month", column=@Column(name="BIRTH_MONTH")),
      @AttributeOverride(name="key.year", column=@Column(name="BIRTH_YEAR"))
    })
    @Column(name="DETAILS")
    @CollectionTable(
            name="EXPERT_CELEBRATIONS",
            joinColumns=@JoinColumn(name="EBC_ID"))
    public Map<Birthday, String> getCelebrations() {
        return celebrations;
    }
    
    @ElementCollection
    @MapKeyColumn(name="Q_DATE")
    @MapKeyTemporal(DATE)
    @Column(name="QUOTE")
    @CollectionTable(
            name="EXPERT_QUOTES",
            joinColumns=@JoinColumn(name="EBC_ID"))
    public Map<Date, String> getQuotes() {
        return quotes;
    }

    //public void setAudio(Collection<byte[]> audio) {
      //  this.audio = audio;
    //}
    
    public void setCelebrations(Map<Birthday, String> celebrations) {
        this.celebrations = celebrations;
    }
    
    public void setQuotes(Map<Date, String> quotes) {
        this.quotes = quotes;
    }
}
