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

level: {
        type: DataTypes.INTEGER,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  analytic_dimensions.associate = (db) => {


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




































    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_1',
      foreignKey: {
          name: 'analytic_level_1Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_2',
      foreignKey: {
          name: 'analytic_level_2Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_3',
      foreignKey: {
          name: 'analytic_level_3Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_4',
      foreignKey: {
          name: 'analytic_level_4Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_5',
      foreignKey: {
          name: 'analytic_level_5Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_6',
      foreignKey: {
          name: 'analytic_level_6Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_7',
      foreignKey: {
          name: 'analytic_level_7Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_8',
      foreignKey: {
          name: 'analytic_level_8Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_9',
      foreignKey: {
          name: 'analytic_level_9Id',
      },
      constraints: false,
    });

    db.analytic_dimensions.hasMany(db.journal_lines, {
      as: 'journal_lines_analytic_level_10',
      foreignKey: {
          name: 'analytic_level_10Id',
      },
      constraints: false,
    });














//end loop



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




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

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



  return analytic_dimensions;
};


