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

recording_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"recording",


"processing",


"ready",


"failed",


"deleted"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

duration_minutes: {
        type: DataTypes.DECIMAL,
      
      

      },

storage_uri: {
        type: DataTypes.TEXT,
      
      

      },

failure_reason: {
        type: DataTypes.TEXT,
      
      

      },

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

  recordings.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.recordings.belongsTo(db.conferences, {
      as: 'conference',
      foreignKey: {
        name: 'conferenceId',
      },
      constraints: false,
    });

    db.recordings.belongsTo(db.users, {
      as: 'requested_by',
      foreignKey: {
        name: 'requested_byId',
      },
      constraints: false,
    });

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



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


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

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



  return recordings;
};


