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

module.exports = (sequelize) => {
    const HandoverFeature = sequelize.define('handoverFeature', {
        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 },
        feature_name: { type: DataTypes.STRING(255), allowNull: false },
        description: { type: DataTypes.TEXT, allowNull: true },
    }, {
        tableName: 'handoverfeatures',
        freezeTableName: true
    });

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

    return HandoverFeature;
};
