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

platform: {
        type: DataTypes.ENUM,
      
      

        values: [

"zoom",


"google_meet",


"teams",


"other"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

join_url: {
        type: DataTypes.TEXT,
      
      

      },

scheduled_start_at: {
        type: DataTypes.DATE,
      
      

      },

scheduled_end_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"joining",


"recording",


"ended",


"failed"

        ],

      },

transcript: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

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

  meetings.associate = (db) => {


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































//end loop



    db.meetings.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.meetings.belongsTo(db.conversations, {
      as: 'conversation',
      foreignKey: {
        name: 'conversationId',
      },
      constraints: false,
    });

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



    db.meetings.hasMany(db.file, {
      as: 'recording_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.meetings.getTableName(),
        belongsToColumn: 'recording_files',
      },
    });


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

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



  return meetings;
};


