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

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"rent",


"utilities",


"salary",


"transport",


"office",


"marketing",


"maintenance",


"bank_fees",


"other"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

expense_date: {
        type: DataTypes.DATE,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

tax_treatment: {
        type: DataTypes.ENUM,
      
      

        values: [

"deductible",


"non_deductible",


"capitalizable",


"unknown"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"rejected"

        ],

      },

reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

review_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  expenses.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.expenses.belongsTo(db.merchants, {
      as: 'merchant',
      foreignKey: {
        name: 'merchantId',
      },
      constraints: false,
    });

    db.expenses.belongsTo(db.receipts, {
      as: 'receipt',
      foreignKey: {
        name: 'receiptId',
      },
      constraints: false,
    });

    db.expenses.belongsTo(db.users, {
      as: 'entered_by',
      foreignKey: {
        name: 'entered_byId',
      },
      constraints: false,
    });

    db.expenses.belongsTo(db.users, {
      as: 'reviewed_by',
      foreignKey: {
        name: 'reviewed_byId',
      },
      constraints: false,
    });

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




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

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



  return expenses;
};


