/**
 * Represents a store on a different computer 
 */

package org.bucksch.zeipis.store;
import org.bucksch.zeipis.all.*;
import org.bucksch.zeipis.core.CoreServer;
import org.bucksch.zeipis.recorder.*;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

public class RemoteStore implements Store
{
  public RemoteStore(String host, String storename)
    throws Misconfiguration
  {
    if (Util.isThisHost(host))
      throw new Misconfiguration("RemoteStore did not get a remote host");
    myHost = host;
    myStoreName = storename; // TODO verify in DB?
  }

  public Source getFile(StoredRecording recording)
  {
    try {
      return new RemoteSource(new URL(CoreServer.me.baseURLForHost(myHost), "/recorded/" + recording.id()));
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
  public Target saveFile(ScheduledRecording recording)
    throws FileNotFoundException
  {
    return new RemoteTarget();
  }
  public long freeSpace()
  {
    // !XXX async
    return 100000000000L;
  }

  public String host() { return myHost; }
  public boolean isLocal() { return false; }
  public String storeName() { return myStoreName; }
  protected String myHost;
  protected String myStoreName;
}
