let createDOMPurify = require('dompurify');
let { JSDOM } = require('jsdom');

let window = new JSDOM('').window;
let DOMPurify = createDOMPurify(window);
var escaped_str = require('querystring')
const Errors = require('../lib/errors')
let pagination = require('../lib/pagination.js')


module.exports = (sequelize, DataTypes) => {
    let TeamMemberRole = sequelize.define('TeamMemberRole', {
        TeamId: {
            type: DataTypes.BIGINT,
            allowNull: false
        },
        RoleId: {
            type: DataTypes.BIGINT
        },
        Role2Id: {
            type: DataTypes.BIGINT
        },
        Role3Id: {
            type: DataTypes.BIGINT
        },
        Role4Id: {
            type: DataTypes.BIGINT
        },
        Role5Id: {
            type: DataTypes.BIGINT
        },
        Role6Id: {
            type: DataTypes.BIGINT
        },
        Role7Id: {
            type: DataTypes.BIGINT
        },
        Role8Id: {
            type: DataTypes.BIGINT
        },
        Role9Id: {
            type: DataTypes.BIGINT
        },
        Role10Id: {
            type: DataTypes.BIGINT
        },
        UserId: {
            type: DataTypes.BIGINT,
            allowNull: false
        },
        createdAt: {
            type: DataTypes.DATE,
            allowNull: false
        },
        updatedAt: {
            type: DataTypes.DATE,
            allowNull: false
        }
    })
    TeamMemberRole.associate = function (models) {
        TeamMemberRole.belongsTo(models.User)
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role2'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role3'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role4'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role5'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role6'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role7'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role8'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role9'})
        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Role10'})

        TeamMemberRole.belongsTo(models.TeamRoles, { as: 'Team' })
    }
    TeamMemberRole.includeOptions = function () {
        let models = sequelize.models

        return [
            {model: models.User, as: 'User', attributes: ['username', 'createdAt', 'id', 'color', 'picture']},
            {model: models.TeamRoles},
        ]
    }
    TeamMemberRole.prototype.leaveTeam = function () {
        this.destroy()
    }
    return TeamMemberRole
}
