import com.healthmarketscience.jackcess.*;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;

public class CreateAccdb {
  static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
  static java.util.Date D(String s){ try { return SDF.parse(s);} catch(Exception e){throw new RuntimeException(e);} }
  static String S(String s){ return s; }

  public static void main(String[] args) throws Exception {
    File f = new File(args[0]);
    if (f.exists()) f.delete();
    Database db = new DatabaseBuilder(f)
        .setFileFormat(Database.FileFormat.V2010).create();

    new TableBuilder("CLIENT")
        .addColumn(new ColumnBuilder("ID_Client", DataType.LONG))
        .addColumn(new ColumnBuilder("Nume", DataType.TEXT))
        .addColumn(new ColumnBuilder("Prenume", DataType.TEXT))
        .addColumn(new ColumnBuilder("Telefon", DataType.TEXT))
        .addColumn(new ColumnBuilder("Email", DataType.TEXT))
        .addColumn(new ColumnBuilder("Oras", DataType.TEXT))
        .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("ID_Client").setPrimaryKey())
        .toTable(db);

    new TableBuilder("ANGAJAT")
        .addColumn(new ColumnBuilder("ID_Angajat", DataType.LONG))
        .addColumn(new ColumnBuilder("Nume", DataType.TEXT))
        .addColumn(new ColumnBuilder("Prenume", DataType.TEXT))
        .addColumn(new ColumnBuilder("Functie", DataType.TEXT))
        .addColumn(new ColumnBuilder("Telefon", DataType.TEXT))
        .addColumn(new ColumnBuilder("Data_Angajare", DataType.SHORT_DATE_TIME))
        .addColumn(new ColumnBuilder("Salariu", DataType.MONEY))
        .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("ID_Angajat").setPrimaryKey())
        .toTable(db);

    new TableBuilder("PRODUS")
        .addColumn(new ColumnBuilder("ID_Produs", DataType.LONG))
        .addColumn(new ColumnBuilder("Denumire", DataType.TEXT))
        .addColumn(new ColumnBuilder("Categorie", DataType.TEXT))
        .addColumn(new ColumnBuilder("Pret", DataType.MONEY))
        .addColumn(new ColumnBuilder("Disponibil", DataType.BOOLEAN))
        .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("ID_Produs").setPrimaryKey())
        .toTable(db);

    new TableBuilder("COMANDA")
        .addColumn(new ColumnBuilder("ID_Comanda", DataType.LONG))
        .addColumn(new ColumnBuilder("ID_Client", DataType.LONG))
        .addColumn(new ColumnBuilder("ID_Angajat", DataType.LONG))
        .addColumn(new ColumnBuilder("Data_Comanda", DataType.SHORT_DATE_TIME))
        .addColumn(new ColumnBuilder("Stare", DataType.TEXT))
        .addColumn(new ColumnBuilder("Metoda_Plata", DataType.TEXT))
        .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("ID_Comanda").setPrimaryKey())
        .toTable(db);

    new TableBuilder("DETALIU_COMANDA")
        .addColumn(new ColumnBuilder("ID_Detaliu", DataType.LONG))
        .addColumn(new ColumnBuilder("ID_Comanda", DataType.LONG))
        .addColumn(new ColumnBuilder("ID_Produs", DataType.LONG))
        .addColumn(new ColumnBuilder("Cantitate", DataType.LONG))
        .addColumn(new ColumnBuilder("Pret_Unitar", DataType.MONEY))
        .addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("ID_Detaliu").setPrimaryKey())
        .toTable(db);

    { Table t = db.getTable("CLIENT");
      t.addRow(new Object[]{ Integer.valueOf(1), S("Popescu"), S("Andrei"), S("0731000001"), S("andrei.popescu@email.com"), S("Brasov") });
      t.addRow(new Object[]{ Integer.valueOf(2), S("Ionescu"), S("Maria"), S("0731000002"), S("maria.ionescu@email.com"), S("Brasov") });
      t.addRow(new Object[]{ Integer.valueOf(3), S("Radulescu"), S("Carmen"), S("0731000003"), S("carmen.radulescu@email.com"), S("Sfantu Gheorghe") });
      t.addRow(new Object[]{ Integer.valueOf(4), S("Stoica"), S("Gabriel"), S("0731000004"), S("gabriel.stoica@email.com"), S("Brasov") });
      t.addRow(new Object[]{ Integer.valueOf(5), S("Dumitru"), S("Vlad"), S("0731000005"), S("vlad.dumitru@email.com"), S("Codlea") });
      t.addRow(new Object[]{ Integer.valueOf(6), S("Marin"), S("Daniela"), S("0731000006"), S("daniela.marin@email.com"), S("Brasov") });
      t.addRow(new Object[]{ Integer.valueOf(7), S("Constantin"), S("Ioana"), S("0731000007"), S("ioana.constantin@email.com"), S("Sacele") });
      t.addRow(new Object[]{ Integer.valueOf(8), S("Georgescu"), S("Bogdan"), S("0731000008"), S("bogdan.georgescu@email.com"), S("Brasov") });
    }
    { Table t = db.getTable("ANGAJAT");
      t.addRow(new Object[]{ Integer.valueOf(1), S("Albu"), S("Iuliana"), S("Manager"), S("0721100100"), D("2019-03-01"), Double.valueOf(6500) });
      t.addRow(new Object[]{ Integer.valueOf(2), S("Munteanu"), S("Razvan"), S("Chelner"), S("0722200200"), D("2021-06-15"), Double.valueOf(4300) });
      t.addRow(new Object[]{ Integer.valueOf(3), S("Dragomir"), S("Elena"), S("Chelner"), S("0723300300"), D("2022-02-10"), Double.valueOf(4200) });
      t.addRow(new Object[]{ Integer.valueOf(4), S("Barbu"), S("Mihai"), S("Bucatar-sef"), S("0724400400"), D("2018-09-01"), Double.valueOf(5800) });
      t.addRow(new Object[]{ Integer.valueOf(5), S("Florea"), S("Ileana"), S("Bucatar"), S("0725500500"), D("2020-11-20"), Double.valueOf(4800) });
      t.addRow(new Object[]{ Integer.valueOf(6), S("Tudor"), S("Cristian"), S("Casier"), S("0726600600"), D("2023-01-05"), Double.valueOf(4100) });
    }
    { Table t = db.getTable("PRODUS");
      t.addRow(new Object[]{ Integer.valueOf(1), S("Gulas unguresc"), S("Fel principal"), Double.valueOf(38.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(2), S("Porkolt de vita"), S("Fel principal"), Double.valueOf(45.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(3), S("Paprikas de pui"), S("Fel principal"), Double.valueOf(40.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(4), S("Langos cu branza"), S("Fel principal"), Double.valueOf(22.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(5), S("Supa Jokai"), S("Supa"), Double.valueOf(24.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(6), S("Supa gulas"), S("Supa"), Double.valueOf(26.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(7), S("Cartofi paprika"), S("Garnitura"), Double.valueOf(14.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(8), S("Salata de varza"), S("Garnitura"), Double.valueOf(10.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(9), S("Kurtoskalacs"), S("Desert"), Double.valueOf(18.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(10), S("Clatite Gundel"), S("Desert"), Double.valueOf(20.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(11), S("Limonada de soc"), S("Bautura"), Double.valueOf(12.0), Boolean.TRUE });
      t.addRow(new Object[]{ Integer.valueOf(12), S("Vin Tokaji (pahar)"), S("Bautura"), Double.valueOf(16.0), Boolean.FALSE });
    }
    { Table t = db.getTable("COMANDA");
      t.addRow(new Object[]{ Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(2), D("2025-05-02"), S("Achitata"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(2), Integer.valueOf(2), Integer.valueOf(3), D("2025-05-02"), S("Achitata"), S("Numerar") });
      t.addRow(new Object[]{ Integer.valueOf(3), Integer.valueOf(3), Integer.valueOf(2), D("2025-05-03"), S("Servita"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(4), Integer.valueOf(4), Integer.valueOf(3), D("2025-05-04"), S("Achitata"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(5), Integer.valueOf(1), Integer.valueOf(2), D("2025-05-05"), S("In preparare"), S("Numerar") });
      t.addRow(new Object[]{ Integer.valueOf(6), Integer.valueOf(5), Integer.valueOf(3), D("2025-05-06"), S("Achitata"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(7), Integer.valueOf(6), Integer.valueOf(2), D("2025-05-07"), S("Achitata"), S("Numerar") });
      t.addRow(new Object[]{ Integer.valueOf(8), Integer.valueOf(7), Integer.valueOf(3), D("2025-05-08"), S("In preparare"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(9), Integer.valueOf(8), Integer.valueOf(2), D("2025-05-09"), S("Servita"), S("Card") });
      t.addRow(new Object[]{ Integer.valueOf(10), Integer.valueOf(2), Integer.valueOf(3), D("2025-05-10"), S("Achitata"), S("Card") });
    }
    { Table t = db.getTable("DETALIU_COMANDA");
      t.addRow(new Object[]{ Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(2), Double.valueOf(38.0) });
      t.addRow(new Object[]{ Integer.valueOf(2), Integer.valueOf(1), Integer.valueOf(9), Integer.valueOf(1), Double.valueOf(18.0) });
      t.addRow(new Object[]{ Integer.valueOf(3), Integer.valueOf(1), Integer.valueOf(11), Integer.valueOf(2), Double.valueOf(12.0) });
      t.addRow(new Object[]{ Integer.valueOf(4), Integer.valueOf(2), Integer.valueOf(2), Integer.valueOf(1), Double.valueOf(45.0) });
      t.addRow(new Object[]{ Integer.valueOf(5), Integer.valueOf(2), Integer.valueOf(6), Integer.valueOf(1), Double.valueOf(26.0) });
      t.addRow(new Object[]{ Integer.valueOf(6), Integer.valueOf(3), Integer.valueOf(3), Integer.valueOf(2), Double.valueOf(40.0) });
      t.addRow(new Object[]{ Integer.valueOf(7), Integer.valueOf(3), Integer.valueOf(7), Integer.valueOf(2), Double.valueOf(14.0) });
      t.addRow(new Object[]{ Integer.valueOf(8), Integer.valueOf(3), Integer.valueOf(11), Integer.valueOf(2), Double.valueOf(12.0) });
      t.addRow(new Object[]{ Integer.valueOf(9), Integer.valueOf(4), Integer.valueOf(4), Integer.valueOf(3), Double.valueOf(22.0) });
      t.addRow(new Object[]{ Integer.valueOf(10), Integer.valueOf(4), Integer.valueOf(8), Integer.valueOf(1), Double.valueOf(10.0) });
      t.addRow(new Object[]{ Integer.valueOf(11), Integer.valueOf(5), Integer.valueOf(1), Integer.valueOf(1), Double.valueOf(38.0) });
      t.addRow(new Object[]{ Integer.valueOf(12), Integer.valueOf(5), Integer.valueOf(5), Integer.valueOf(1), Double.valueOf(24.0) });
      t.addRow(new Object[]{ Integer.valueOf(13), Integer.valueOf(6), Integer.valueOf(2), Integer.valueOf(2), Double.valueOf(45.0) });
      t.addRow(new Object[]{ Integer.valueOf(14), Integer.valueOf(6), Integer.valueOf(10), Integer.valueOf(2), Double.valueOf(20.0) });
      t.addRow(new Object[]{ Integer.valueOf(15), Integer.valueOf(6), Integer.valueOf(11), Integer.valueOf(2), Double.valueOf(12.0) });
      t.addRow(new Object[]{ Integer.valueOf(16), Integer.valueOf(7), Integer.valueOf(3), Integer.valueOf(1), Double.valueOf(40.0) });
      t.addRow(new Object[]{ Integer.valueOf(17), Integer.valueOf(7), Integer.valueOf(9), Integer.valueOf(2), Double.valueOf(18.0) });
      t.addRow(new Object[]{ Integer.valueOf(18), Integer.valueOf(8), Integer.valueOf(4), Integer.valueOf(2), Double.valueOf(22.0) });
      t.addRow(new Object[]{ Integer.valueOf(19), Integer.valueOf(8), Integer.valueOf(6), Integer.valueOf(2), Double.valueOf(26.0) });
      t.addRow(new Object[]{ Integer.valueOf(20), Integer.valueOf(9), Integer.valueOf(1), Integer.valueOf(4), Double.valueOf(38.0) });
      t.addRow(new Object[]{ Integer.valueOf(21), Integer.valueOf(9), Integer.valueOf(7), Integer.valueOf(4), Double.valueOf(14.0) });
      t.addRow(new Object[]{ Integer.valueOf(22), Integer.valueOf(9), Integer.valueOf(11), Integer.valueOf(4), Double.valueOf(12.0) });
      t.addRow(new Object[]{ Integer.valueOf(23), Integer.valueOf(10), Integer.valueOf(2), Integer.valueOf(1), Double.valueOf(45.0) });
      t.addRow(new Object[]{ Integer.valueOf(24), Integer.valueOf(10), Integer.valueOf(10), Integer.valueOf(1), Double.valueOf(20.0) });
    }

    new RelationshipBuilder("CLIENT", "COMANDA").addColumns("ID_Client", "ID_Client").setReferentialIntegrity().toRelationship(db);
    new RelationshipBuilder("ANGAJAT", "COMANDA").addColumns("ID_Angajat", "ID_Angajat").setReferentialIntegrity().toRelationship(db);
    new RelationshipBuilder("COMANDA", "DETALIU_COMANDA").addColumns("ID_Comanda", "ID_Comanda").setReferentialIntegrity().toRelationship(db);
    new RelationshipBuilder("PRODUS", "DETALIU_COMANDA").addColumns("ID_Produs", "ID_Produs").setReferentialIntegrity().toRelationship(db);

    db.close();
    System.out.println("OK: " + f.getAbsolutePath());
  }
}
