const { Sequelize } = require('sequelize');

const sequelize = new Sequelize({
  dialect: 'sqlite',
  storage: 'data/leviathan.db'
});

const Hardware = require('./hardware')(sequelize);
const Benchmark = require('./benchmark')(sequelize);
const Test = require('./test')(sequelize);
const Result = require('./result')(sequelize);

// Hardware/Test one-to-many
Hardware.hasMany(Test);
Test.belongsTo(Hardware);

// Benchmark/Test many-to-many
Benchmark.belongsToMany(Test, { through: 'tests_benchmarks' });
Test.belongsToMany(Benchmark, { through: 'tests_benchmarks' });

// Result/Benchmark many-to-one
Result.belongsTo(Benchmark);
Benchmark.hasMany(Result);

// Result/Test many-to-one
Result.belongsTo(Test);
Test.hasMany(Result);

module.exports = sequelize;
