import sale.*;
import log.*;
import users.*;
import data.*;
import data.ooimpl.*;

import java.io.*;
import java.util.*;


/**
 * Diese Klasse ist der "Shop" der Anwendung. Sie stellt das Grundgerüst
 * für die Anwendung dar.
 */
public class VideoMachine extends Shop
{
   
  //// attributes ////////////////////////////////////////////////////////////
   
  // Liste aller registrierten Kunden
  private static Set customerSet = new HashSet();
  //// constructor ///////////////////////////////////////////////////////////
   
  /**
   * Konstruktor. Erzeugt ein neues Objekt vom Typ VideoAutomat.
   */
  public VideoMachine()
  {
    super();
   
    // Name und Preis fuer die Standart-Katalogeintraege
    String[] videos = {"Video 01", "Video 02", "Video 03", "Video 04",
                       "Video 05", "Video 06", "Video 07", "Video 08",
                       "Video 09", "Video 10"};
    int[] buy  = {5000, 5000, 5000, 5000, 5000, 4000, 4000, 4000, 3000, 3000};
    int[] sell = {4000, 4000, 4000, 4000, 3500, 3500, 3500, 3500, 3000, 3000};
        
    // Eintragung in den Catalog und den Stock
    Catalog videoCatalog = new CatalogImpl("Video-Catalog");
    addCatalog(videoCatalog);
      
    for (int i = 0; i < videos.length; i++) {
      videoCatalog.add(new VideoCassette (videos[i], new QuoteValue
        (new IntegerValue (buy[i]), new IntegerValue (sell[i]))), null);
    }
      
    CountingStock cs = new CountingStockImpl("Video-Countingstock",
                                             (CatalogImpl)videoCatalog);
    addStock(cs);
      
    // Erstellen eines Bestands von je 5 Videos (sollte spaeter
    // vom Manager uebernommen werden
    Iterator cassettes = videoCatalog.keySet(null).iterator();
    while (cassettes.hasNext()) {
      cs.add((String)cassettes.next(), 5, null);
    }
      
    // Anlegen einer Waehrung und Erstellen eines dazugehoerigen
    // Geldbestandes
    addCatalog(new CurrencyImpl("DM"));
     
    MoneyBag coinSlot = new MoneyBagImpl("coin slot",
                                         (CurrencyImpl)getCatalog("DM"));
    coinSlot.add(CurrencyImpl.PFENNIG_STCK_1, 100000, null);
    addStock(coinSlot);
  }
   
   
  //// public methods ///////////////////////////////////////////////////////
   
  /**
   * Die Main-Methode startet die Anwendung.
   */
  public static void main (String[] args)
  {
    // neuen Videoautomaten erzeugen
    VideoMachine vidMachine = new VideoMachine();
    setTheShop(vidMachine);
            
    // Titel setzen und starten
    vidMachine.setShopFrameTitle("Videoverleihautomat *** HOMECINEMA *** 24h");
    vidMachine.start();
      
    vidMachine.getShopFrame().setSize(640,480);
    vidMachine.getShopFrame().validate();
  }
   
 /**
  * Beendet das Programm ohne den Stand abzuspeichern.
  */
  public void quit()
  {
    if (Shop.getTheShop().shutdown (false)) {
      System.exit (0);
    }
  }
}