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

bank_name: {
        type: DataTypes.TEXT,
      
      

      },

payment_no: {
        type: DataTypes.TEXT,
      
      

      },

payment_date: {
        type: DataTypes.DATE,
      
      

      },

payment_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

principal: {
        type: DataTypes.DECIMAL,
      
      

      },

interest: {
        type: DataTypes.DECIMAL,
      
      

      },

remaining_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"paid",


"overdue",


"skipped",


"restructured"

        ],

      },

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

  loan_schedules.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.loan_schedules.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.loan_schedules.belongsTo(db.vehicles, {
      as: 'vehicle',
      foreignKey: {
        name: 'vehicleId',
      },
      constraints: false,
    });




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

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



  return loan_schedules;
};


