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

start_payment_date: {
        type: DataTypes.DATE,

      },

payment_date: {
        type: DataTypes.DATE,

      },

last_payment_paid_date: {
        type: DataTypes.DATE,

      },

sort: {
        type: DataTypes.INTEGER,

      },

deduct_amount: {
        type: DataTypes.DECIMAL,

      },

deduct_paid_amount: {
        type: DataTypes.DECIMAL,

      },

interval: {
        type: DataTypes.INTEGER,

      },

interest_amount: {
        type: DataTypes.DECIMAL,

      },

commission_amount: {
        type: DataTypes.DECIMAL,

      },

total_amount: {
        type: DataTypes.DECIMAL,

      },

total_paid_amount: {
        type: DataTypes.DECIMAL,

      },

penalty_amount: {
        type: DataTypes.DECIMAL,

      },

pending_amount: {
        type: DataTypes.DECIMAL,

      },

cross_amount: {
        type: DataTypes.DECIMAL,

      },

remark: {
        type: DataTypes.TEXT,

      },

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

  payments.associate = (db) => {

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

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

  return payments;
};

