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

operation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"close_profit_and_loss",


"adjust_nature",


"closing_voucher",


"opening_voucher",


"currency_revaluation"

        ],

      },

operation_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"generated",


"posted",


"canceled"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

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

    db.year_end_operations.belongsTo(db.journal_vouchers, {
      as: 'generated_voucher',
      foreignKey: {
        name: 'generated_voucherId',
      },
      constraints: false,
    });




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

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



  return year_end_operations;
};


