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

module.exports = (sequelize) => {
    const HandoverTest = sequelize.define('handoverTest', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        creation: { type: DataTypes.DATE, allowNull: false },
        modified: { type: DataTypes.DATE, allowNull: false },
        modified_by: { type: DataTypes.INTEGER, allowNull: false },
        owner: { type: DataTypes.INTEGER, allowNull: false },
        enabled: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true },
        
        handover_id: { type: DataTypes.INTEGER, allowNull: false },
        module_name: { type: DataTypes.STRING(100), allowNull: true },
        test_scenario: { type: DataTypes.TEXT, allowNull: true },
        test_type: { type: DataTypes.STRING(100), allowNull: false },
        test_result: { type: DataTypes.STRING(50), allowNull: false },
        status: { type: DataTypes.STRING(50), allowNull: true },
        notes: { type: DataTypes.TEXT, allowNull: true },
    }, {
        tableName: 'handovertests',
        freezeTableName: true
    });

    HandoverTest.associate = (models) => {
        HandoverTest.belongsTo(models.HandoverCompletion, { foreignKey: "handover_id", as: "handover" });
        HandoverTest.belongsTo(models.User, { foreignKey: "modified_by", as: "modifier" });
    };

    return HandoverTest;
};
