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

code: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

prefix: {
        type: DataTypes.TEXT,
      
      

      },

next_number: {
        type: DataTypes.INTEGER,
      
      

      },

padding: {
        type: DataTypes.INTEGER,
      
      

      },

reset_policy: {
        type: DataTypes.ENUM,
      
      

        values: [

"never",


"yearly",


"monthly",


"daily"

        ],

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  numbering_profiles.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity


































    db.numbering_profiles.hasMany(db.journal_voucher_types, {
      as: 'journal_voucher_types_numbering_profile',
      foreignKey: {
          name: 'numbering_profileId',
      },
      constraints: false,
    });
















//end loop



    db.numbering_profiles.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });




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

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



  return numbering_profiles;
};


