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

year: {
        type: DataTypes.INTEGER,
      
      

      },

month: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"OPEN",


"CLOSED",


"LOCKED"

        ],

      },

openedAt: {
        type: DataTypes.DATE,
      
      

      },

closedAt: {
        type: DataTypes.DATE,
      
      

      },

lockedAt: {
        type: DataTypes.DATE,
      
      

      },

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

  fiscal_periods.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.fiscal_periods.belongsTo(db.users, {
      as: 'closedByUser',
      foreignKey: {
        name: 'closedByUserId',
      },
      constraints: false,
    });

    db.fiscal_periods.belongsTo(db.users, {
      as: 'lockedByUser',
      foreignKey: {
        name: 'lockedByUserId',
      },
      constraints: false,
    });




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

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



  return fiscal_periods;
};


