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

module.exports = (sequelize) => {
    const AppTeam = sequelize.define('appTeam', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        app_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'Apps',
                key: 'id'
            },
            onDelete: 'CASCADE'
        },
        team_member_name: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        role: {
            type: DataTypes.STRING(255),
            allowNull: false
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: true
        },
    }, {
        tableName: 'appTeams',
    }, {
        freezeTableName: true
    });

    AppTeam.associate = (models) => {
        AppTeam.belongsTo(models.App, {
            foreignKey: 'app_id',
            as: 'app',
            onDelete: 'CASCADE'
        });
    };

    return AppTeam;
};

