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

media_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"video",


"document"

        ],

      },

title_ar: {
        type: DataTypes.TEXT,
      
      

      },

alt_text_ar: {
        type: DataTypes.TEXT,
      
      

      },

source_note_ar: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  media_library.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.media_library.hasMany(db.file, {
      as: 'images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.media_library.getTableName(),
        belongsToColumn: 'images',
      },
    });

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


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

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



  return media_library;
};


