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

module.exports = (sequelize) => {
    const WorkflowSetting = sequelize.define(
        "workflowsetting",
        {
            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: true },
            owner: { type: DataTypes.INTEGER, allowNull: true },
            enabled: { type: DataTypes.BOOLEAN, allowNull: false },

            limit: { type: DataTypes.INTEGER, allowNull: true },
            type: { type: DataTypes.STRING(100), allowNull: true },

            // fk
            doctype_id: { type: DataTypes.INTEGER, allowNull: false },
        },
        {
            tableName: "workflowsettings",
            freezeTableName: true,
        }
    );

    WorkflowSetting.associate = (models) => {
        WorkflowSetting.belongsTo(models.DocType, { foreignKey: 'doctype_id', as: 'doctype' });
    }

    return WorkflowSetting;
};
