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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"S3",


"AZURE_BLOB",


"GCS",


"LOCAL"

        ],

      },

file_key: {
        type: DataTypes.TEXT,
      
      

      },

file_name: {
        type: DataTypes.TEXT,
      
      

      },

mime_type: {
        type: DataTypes.TEXT,
      
      

      },

size_bytes: {
        type: DataTypes.INTEGER,
      
      

      },

file_url: {
        type: DataTypes.TEXT,
      
      

      },

checksum_sha256: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

uploaded_by: {
        type: DataTypes.TEXT,
      
      

      },

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

  cost_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.cost_files.belongsTo(db.cost_items, {
      as: 'cost_item',
      foreignKey: {
        name: 'cost_itemId',
      },
      constraints: false,
    });




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

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



  return cost_files;
};


