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

name: {
        type: DataTypes.TEXT,
      
      

      },

kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"font",


"video",


"other"

        ],

      },

size: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  assets.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.assets.belongsTo(db.users, {
      as: 'uploaded_by',
      foreignKey: {
        name: 'uploaded_byId',
      },
      constraints: false,
    });

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



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


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

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



  return assets;
};


