package org.bdgp.MMSlide.DB;

import org.micromanager.api.ImageCache;

import mmcorej.TaggedImage;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class Image {
    @DatabaseField(generatedId=true, canBeNull=false) private int id;
    @DatabaseField(canBeNull=false) private int slideId;
    @DatabaseField(canBeNull=false) private int slidePosId;
    @DatabaseField(canBeNull=false,uniqueCombo=true) private int acquisitionId;
    @DatabaseField(canBeNull=false,uniqueCombo=true) private int channel;
    @DatabaseField(canBeNull=false,uniqueCombo=true) private int slice;
    @DatabaseField(canBeNull=false,uniqueCombo=true) private int frame;
    @DatabaseField(canBeNull=false,uniqueCombo=true) private int position;
    
    public Image() {}
    public Image (int slideId, int slidePosId, Acquisition acquisition, int channel, int slice, int frame, int position) {
        this.slideId = slideId;
        this.slidePosId = slidePosId;
        this.channel = channel;
        this.slice = slice;
        this.frame = frame;
        this.position = position;
        if (acquisition == null) throw new RuntimeException("Acquisition is null");
        this.acquisitionId = acquisition.getId();
    }
    public int getId() {return this.id;}
    public String getName() {return String.format("I%05d", this.id);}

    public int getSlideId() {return this.slideId;}
    public int getSlidePosId() {return this.slidePosId;}
    public int getAcquisitionId() {return this.acquisitionId;}
    public int getChannel() {return this.channel;}
    public int getSlice() {return this.slice;}
    public int getFrame() {return this.frame;}
    public int getPosition() {return this.position;}
    
    public TaggedImage getImage(ImageCache imageCache) {
    	return imageCache.getImage(this.channel, this.slice, this.frame, this.position);
    }
}

@@ -1262,16 +1262,375 @@
 ;%0A    %7D%0A
+    public Image (int slideId, int slidePosId, int acquisitionId, int channel, int slice, int frame, int position) %7B%0A        this.slideId = slideId;%0A        this.slidePosId = slidePosId;%0A        this.channel = channel;%0A        this.slice = slice;%0A        this.frame = frame;%0A        this.position = position;%0A        this.acquisitionId = acquisitionId;%0A    %7D%0A
     publ
@@ -2256,10 +2256,340 @@
 ;%0A    %7D%0A
+    %0A    public String toString() %7B%0A    %09return String.format(%0A    %09%09%09%22Image(slideId=%25d, slidePosId=%25d, channel=%25d, slice=%25d, frame=%25d, position=%25d, acquisitionId=%25d)%22,%0A    %09%09%09this.slideId,%0A    %09%09%09this.slidePosId,%0A    %09%09%09this.channel, %0A    %09%09%09this.slice,%0A    %09%09%09this.frame,%0A    %09%09%09this.position,%0A    %09%09%09this.acquisitionId);%0A    %7D%0A
 %7D%0A

add Image.toString() and extra constructor