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

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.ENUM,
      
      

        values: [

"CDF",


"USD"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"rejected",


"cancelled"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

justification: {
        type: DataTypes.TEXT,
      
      

      },

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

  budget_reallocations.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.budget_reallocations.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.budget_reallocations.belongsTo(db.fiscal_years, {
      as: 'fiscal_year',
      foreignKey: {
        name: 'fiscal_yearId',
      },
      constraints: false,
    });

    db.budget_reallocations.belongsTo(db.budget_lines, {
      as: 'from_budget_line',
      foreignKey: {
        name: 'from_budget_lineId',
      },
      constraints: false,
    });

    db.budget_reallocations.belongsTo(db.budget_lines, {
      as: 'to_budget_line',
      foreignKey: {
        name: 'to_budget_lineId',
      },
      constraints: false,
    });

    db.budget_reallocations.belongsTo(db.users, {
      as: 'requested_by_user',
      foreignKey: {
        name: 'requested_by_userId',
      },
      constraints: false,
    });




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

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



  return budget_reallocations;
};


