/*
 * Copyright 2008 Estalea, Inc. All rights reserved.
 * This software is the proprietary information of Estalea, Inc.
 */

package org.forkalsrud.album.exif;

import java.io.File;
import java.util.Date;


/**
 * Represents one item inside the album, typically file or directory, aka photo or album
 *
 * @author knut
 */
public abstract class Entry {

	/**
	 * The object in the file system that this entry represents
	 */
	File file;
	Thumbnail thumbnail;
    String caption;
    Date date;
    Entry next;
    Entry prev;
    Entry parent;
    String type;

    protected Entry(File file, String type) {
    	this.file = file;
    	this.type = type;
    }

    protected Entry(Entry other) {
        this(other.file, other.type);
        this.thumbnail = other.thumbnail;
        this.caption = other.caption;
        this.date = other.date;
        /*
        this.next = other.next;
        this.prev = other.prev;
        this.parent = other.parent;
        */
    }

    public String getType() {
        return this.type;
    }


    /**
     * @return Returns the name.
     */
    public String getName() {
        return file.getName();
    }

    
	public Thumbnail getThumbnail() {
		return thumbnail;
	}


	public void setThumbnail(Thumbnail thumbnail) {
		this.thumbnail = thumbnail;
	}


	/**
     * @return Returns the caption.
     */
    public String getCaption() {
        return caption;
    }


    
    /**
     * @param caption The caption to set.
     */
    public void setCaption(String caption) {
        this.caption = caption;
    }


    
    /**
     * @return Returns the date.
     */
    public Date getDate() {
        return date;
    }


    
    /**
     * @param date The date to set.
     */
    public void setDate(Date date) {
        this.date = date;
    }


    
    public Entry prev() {
        return prev;
    }
    public Entry next() {
        return next;
    }
    public Entry parent() {
    	return parent;
    }
    public File getPath() {
    	return file;
    }

    public Date getEarliest() {
        return getDate();
    }


    public boolean groupByYear() {
        return false;
    }

    
    
    protected void appendDiagnostic(StringBuilder buf) {
        buf.append("file: ");
        appendFile(buf);
        buf.append(",");
        buf.append("thumbnail: ");
        if (thumbnail != null) {
            buf.append(thumbnail);
        } else {
            buf.append("null");
        }
        buf.append(",");
        buf.append("caption: ");
        if (caption != null) {
            buf.append(caption);
        } else {
            buf.append("null");
        }
        buf.append(",");
        buf.append("date: ");
        buf.append(date);
        buf.append(",");
        buf.append("next: ");
        if (next != null) {
            next.appendFile(buf);
        } else {
            buf.append("null");
        }
        buf.append(",");
        buf.append("prev: ");
        if (prev != null) {
            prev.appendFile(buf);
        } else {
            buf.append("null");
        }
        buf.append(",");
        buf.append("type: ");
        buf.append(type);
    }

    
    protected void appendFile(StringBuilder buf) {
        if (file != null) {
            buf.append(file.getAbsolutePath());
        } else {
            buf.append("null");
        }
    }
    
    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder("{");
        appendDiagnostic(buf);
        buf.append("}");
        return buf.toString();
    }
}
