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 conferences = sequelize.define(
    'conferences',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

conference_key: {
        type: DataTypes.TEXT,
      
      

      },

conference_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"ad_hoc",


"always_on"

        ],

      },

conference_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"created",


"running",


"ended",


"failed"

        ],

      },

scheduled_start_at: {
        type: DataTypes.DATE,
      
      

      },

scheduled_end_at: {
        type: DataTypes.DATE,
      
      

      },

actual_start_at: {
        type: DataTypes.DATE,
      
      

      },

actual_end_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

participant_limit: {
        type: DataTypes.INTEGER,
      
      

      },

region_preference: {
        type: DataTypes.ENUM,
      
      

        values: [

"auto",


"us",


"eu",


"apac",


"sa",


"me"

        ],

      },

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

  conferences.associate = (db) => {


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


















    db.conferences.hasMany(db.participants, {
      as: 'participants_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });



    db.conferences.hasMany(db.sfu_allocations, {
      as: 'sfu_allocations_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });


    db.conferences.hasMany(db.breakout_rooms, {
      as: 'breakout_rooms_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });


    db.conferences.hasMany(db.chat_channels, {
      as: 'chat_channels_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });





    db.conferences.hasMany(db.recordings, {
      as: 'recordings_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });


    db.conferences.hasMany(db.transcripts, {
      as: 'transcripts_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });







    db.conferences.hasMany(db.ai_companion_sessions, {
      as: 'ai_companion_sessions_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });



















    db.conferences.hasMany(db.quality_reports, {
      as: 'quality_reports_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });



    db.conferences.hasMany(db.conference_events, {
      as: 'conference_events_conference',
      foreignKey: {
          name: 'conferenceId',
      },
      constraints: false,
    });



//end loop



    db.conferences.belongsTo(db.rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });

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




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

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



  return conferences;
};


