package org.bucksch.zeipis.store;
import org.bucksch.zeipis.all.*;
import org.bucksch.zeipis.recorder.Recording;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StoredRecording extends Recording
{
  public StoredRecording(int recordingid)
    throws Misconfiguration, SQLException
  {
    super(recordingid);
    readDatabase("SELECT * FROM recording LEFT JOIN film USING (filmid) LEFT JOIN store USING (storename) WHERE recordid = " + myID);
  }
  protected void readDatabaseResult(ResultSet rs)
    throws SQLException, Misconfiguration
  {
    super.readDatabaseResult(rs);
    if ( ! rs.getBoolean("done"))
      throw new SQLException("Recording ID " + myID + " is not done yet"); // TODO localize
    myRelFilename = rs.getString("filename");
    myAbsFilename = rs.getString("directoryname") + rs.getString("filename");
    String storeName = rs.getString("storename");
    myStore = CoreData.me.myStores.get(storeName);
    if (myStore == null)
      throw new Misconfiguration("Store " + storeName + " for recording " + myID + " not found");
    myIsLocal = Util.isThisHost(myStore.host());

    myIsSeen = rs.getBoolean("seen");
    myDoKeep = rs.getBoolean("keep");
  }

  // Getter
  public String relFilename() { return myRelFilename; }
  public String absFilename() { return myAbsFilename; }
  public Store store() { return myStore; }
  public boolean isLocal() { return myIsLocal; }
  public boolean seen() { return myIsSeen; }
  public void setSeen(boolean myIsSeen) { this.myIsSeen = myIsSeen; }
  public boolean keep() { return myDoKeep; }
  public void setKeep(boolean myDoKeep) { this.myDoKeep = myDoKeep; }

  // Data
  protected String myHost;
  protected Store myStore;
  protected String myRelFilename;
  protected String myAbsFilename;
  protected boolean myIsLocal;
  protected boolean myIsSeen;
  protected boolean myDoKeep;
}
