const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const conference_templates = sequelize.define(
    'conference_templates',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

e2ee_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

lobby_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

recording_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

transcription_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

canvas_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

default_layout_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"auto",


"grid",


"speaker",


"presentation"

        ],

      },

max_participants: {
        type: DataTypes.INTEGER,
      
      

      },

template_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"draft",


"archived"

        ],

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  conference_templates.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity















    db.conference_templates.hasMany(db.rooms, {
      as: 'rooms_conference_template',
      foreignKey: {
          name: 'conference_templateId',
      },
      constraints: false,
    });









































//end loop



    db.conference_templates.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.conference_templates.belongsTo(db.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

    db.conference_templates.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.conference_templates.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.conference_templates.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return conference_templates;
};


