import log.Loggable;
import log.LogEntry;
import data.ooimpl.StoringStockItemDBEntry;


/**
 * Definiert Die Schnittstelle <Code>Loggable</CODE>.
 */
public class MyLoggable implements Loggable
{
   
  //// attributes ////////////////////////////////////////////////////////////
   
  String name;  
  String customerID;
  Object date;
  boolean rent;  // wird ein Ausleihvorgang(true)
                 // oder ein Rückgabevorgang(false) geloggt
   
  //// constructor ///////////////////////////////////////////////////////////
   
  /**
   * Der Konstruktor legt ein neues Objekt der Klasse <CODE>MyLoggable</CODE>
   * an, wobei der Konstruktor von <CODE>Loggable</CODE> aufgerufen wird,
   * und die &uuml;bergebenen Variablen zugewiesen werden. Diese sind
   * wichtig f&uuml;r die Erstellung des Log-Eintrags.
   */
  public MyLoggable(String name, String customerID, Object date)
  {
    super();
    this.name = name;
    this.customerID = customerID;
    this.date = date;
    rent = true;
  }
   
  /**
   * Der Konstruktor wird vom GiveBackProcess aufgerufen,
   * das LogEntry wird dadurch beeinflusst
   */
  public MyLoggable(StoringStockItemDBEntry cassetteItem, Customer customer, Object date)
  {
    super();
    name = cassetteItem.getSecondaryKey();
    this.customerID = customer.getCustomerID();
    this.date = date;
    rent = false;
  }
   
  //// public methods ////////////////////////////////////////////////////////
   
  /**
   * Holt sich den Log-Eintrag, der aus den &uuml;bergebenen Daten
   * zusammengestellt wird. Dazu wird die extra implementierte
   * Klasse <CODE>MyLogEntry</CODE> genutzt.
   */
  public LogEntry getLogData()
  {
    return new MyLogEntry(name, customerID, date, rent);
  }
}



/**
 * &Uuml;berschreibt die Klasse <Code>LogEntry</CODE> um einen
 * selbstdefinierten Log-Eintrag zu erm&ouml;glichen.
 */
class MyLogEntry extends LogEntry
{
   
  //// attributes ////////////////////////////////////////////////////////////
   
  String name;
  String customerID;
  Object date;
  boolean rent;  // wird ein Ausleihvorgang(true)
                 // oder ein Rückgabevorgang(false) geloggt
   
  //// constructor ///////////////////////////////////////////////////////////
   
  /**
   * Der Konstruktor legt ein neues Objekt der Klasse <CODE>MyLogEntry</CODE>
   * an, wobei der Konstruktor von <CODE>LogEntry</CODE> aufgerufen wird,
   * und die &uuml;bergebenen Variablen zugewiesen werden. Diese sind
   * wichtig f&uuml;r die Erstellung des Log-Eintrags.
   */
  public MyLogEntry(String name, String customerID, Object date, boolean rent)
  {
    super();
    this.name = name;
    this.customerID = customerID;
    this.date = date;
    this.rent = rent;
  }
   
    
  //// public methods ////////////////////////////////////////////////////////
   
  /**
   * Spezifiziert das Aussehen des Log-Eintrags.
   */
  public String toString()
  {
    if (rent)
      return name + " rent by customer " + customerID + " (ID) at turn " + date;
    else
      return "customer "+ customerID + " (ID) gave back " + name + " at turn " + date;
  }
}