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

code: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

engine: {
        type: DataTypes.ENUM,
      
      

        values: [

"stimulsoft",


"crystal_reports",


"ssrs"

        ],

      },

path_or_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,
    },
  );

  report_definitions.associate = (db) => {


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










































    db.report_definitions.hasMany(db.report_runs, {
      as: 'report_runs_report_definition',
      foreignKey: {
          name: 'report_definitionId',
      },
      constraints: false,
    });








//end loop



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




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

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



  return report_definitions;
};


