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

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"revenue",


"cogs",


"payroll",


"rent",


"software",


"marketing",


"travel",


"tax",


"interest",


"other_expense",


"other_income"

        ],

      },

planned_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

actual_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  budget_lines.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_lines.belongsTo(db.budgets, {
      as: 'budget',
      foreignKey: {
        name: 'budgetId',
      },
      constraints: false,
    });

    db.budget_lines.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return budget_lines;
};


