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

caption: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  job_attachments.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.job_attachments.belongsTo(db.jobs, {
      as: 'job',
      foreignKey: {
        name: 'jobId',
      },
      constraints: false,
    });



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


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

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



  return job_attachments;
};


