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

module.exports = (sequelize) => {
    const ProjectTeam = sequelize.define('projectteam', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        project_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'Projects',
                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: 'projectteams',
    }, {
        freezeTableName: true 
    });

    ProjectTeam.associate = (models) => {
        ProjectTeam.belongsTo(models.Project, {
            foreignKey: 'project_id',
            as: 'project',
            onDelete: 'CASCADE'
        });
    };

    return ProjectTeam;
};
