package org.bucksch.zeipis.recorder;
import org.bucksch.zeipis.all.*;

import java.util.Date;
import java.sql.*;

abstract public class ScheduledRecording extends Recording
{
  public ScheduledRecording(int recordingid)
    throws Misconfiguration, SQLException
  {
    super(recordingid);
    readDatabase("SELECT * FROM recording INNER JOIN recording_plan ON (recording.recordid = recording_plan.recordid) INNER JOIN film ON (recording.filmid = film.filmid) INNER JOIN broadcast ON (recording.filmid = broadcast.filmid) WHERE recording.recordid = " + myID + " AND starttime > NOW() ORDER BY starttime ASC");
  }
  protected ScheduledRecording(ResultSet rs)
    throws Misconfiguration, SQLException
  {
    super(rs.getInt("recordid"));
    readDatabaseResult(rs);
  }
  protected void readDatabaseResult(ResultSet rs)
    throws SQLException, Misconfiguration
  {
    super.readDatabaseResult(rs);
    myStarttime = rs.getTimestamp("starttime"); // there's no getDatetime(), and getDate() truncates time
    myEndtime = rs.getTimestamp("endtime");
    myStationID = rs.getInt("stationid");
    myRecordID = rs.getInt("recordid");
    myBroadcastID = rs.getInt("broadcastid");
    myFilmID = rs.getInt("filmid");
  }

  public String toString()
  {
    return myStarttime + " - " + myEndtime + " stationID " + myStationID + " " + super.toString();
  }

  // Getter
  public Date starttime() { return myStarttime; };
  public Date endtime() { return myEndtime; };
  public int stationID() { return myStationID; };
  public int broadcastID() { return myBroadcastID; };
  public int recordID() { return myRecordID; };
  public int filmID() { return myFilmID; };

  // Data
  protected Date myStarttime;
  protected Date myEndtime;
  protected int myStationID;
  protected int myRecordID;
  protected int myBroadcastID;
  protected int myFilmID;
}
