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

file_name: {
        type: DataTypes.TEXT,
      
      

      },

content_type: {
        type: DataTypes.TEXT,
      
      

      },

size_bytes: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"uploading",


"processing",


"done",


"failed"

        ],

      },

progress_percent: {
        type: DataTypes.INTEGER,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  upload_files.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.upload_files.belongsTo(db.upload_sessions, {
      as: 'upload_session',
      foreignKey: {
        name: 'upload_sessionId',
      },
      constraints: false,
    });

    db.upload_files.belongsTo(db.media_items, {
      as: 'media_item',
      foreignKey: {
        name: 'media_itemId',
      },
      constraints: false,
    });

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




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

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



  return upload_files;
};


