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

recommendation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"cost_cut",


"pricing",


"cash_management",


"collections",


"fundraising",


"forecast_update",


"process_improvement"

        ],

      },

priority: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high"

        ],

      },

title_text: {
        type: DataTypes.TEXT,
      
      

      },

rationale: {
        type: DataTypes.TEXT,
      
      

      },

action_steps: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"proposed",


"in_progress",


"done",


"dismissed"

        ],

      },

created_on: {
        type: DataTypes.DATE,
      
      

      },

due_on: {
        type: DataTypes.DATE,
      
      

      },

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

  recommendations.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.recommendations.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.recommendations.belongsTo(db.users, {
      as: 'assigned_to',
      foreignKey: {
        name: 'assigned_toId',
      },
      constraints: false,
    });

    db.recommendations.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return recommendations;
};


