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

bankCode: {
        type: DataTypes.ENUM,
      
      

        values: [

"BDO",


"BPI",


"METROBANK",


"PNB",


"RCBC",


"UNIONBANK"

        ],

      },

fileFormat: {
        type: DataTypes.ENUM,
      
      

        values: [

"CSV",


"TXT",


"XLSX"

        ],

      },

totalAmount: {
        type: DataTypes.DECIMAL,
      
      

      },

recordCount: {
        type: DataTypes.INTEGER,
      
      

      },

generatedAt: {
        type: DataTypes.DATE,
      
      

      },

submittedAt: {
        type: DataTypes.DATE,
      
      

      },

fileHash: {
        type: DataTypes.TEXT,
      
      

      },

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

  bank_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.bank_files.belongsTo(db.payroll_runs, {
      as: 'payrollRun',
      foreignKey: {
        name: 'payrollRunId',
      },
      constraints: false,
    });

    db.bank_files.belongsTo(db.users, {
      as: 'generatedByUser',
      foreignKey: {
        name: 'generatedByUserId',
      },
      constraints: false,
    });



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


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

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



  return bank_files;
};


