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

lc_number: {
        type: DataTypes.TEXT,
      
      

      },

issue_date: {
        type: DataTypes.DATE,
      
      

      },

expiry_date: {
        type: DataTypes.DATE,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"opened",


"utilized",


"closed",


"canceled"

        ],

      },

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

  letters_of_credit.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.letters_of_credit.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });

    db.letters_of_credit.belongsTo(db.banks, {
      as: 'bank',
      foreignKey: {
        name: 'bankId',
      },
      constraints: false,
    });

    db.letters_of_credit.belongsTo(db.counterparties, {
      as: 'counterparty',
      foreignKey: {
        name: 'counterpartyId',
      },
      constraints: false,
    });

    db.letters_of_credit.belongsTo(db.currencies, {
      as: 'currency',
      foreignKey: {
        name: 'currencyId',
      },
      constraints: false,
    });



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


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

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



  return letters_of_credit;
};


