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

title: {
        type: DataTypes.TEXT,
      
      

      },

audience: {
        type: DataTypes.ENUM,
      
      

        values: [

"investor_vc",


"bank_lender",


"strategic_partner",


"seller_owner",


"internal"

        ],

      },

stage: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"review",


"final"

        ],

      },

executive_summary: {
        type: DataTypes.TEXT,
      
      

      },

full_plan: {
        type: DataTypes.TEXT,
      
      

      },

assumptions: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  business_plan_versions.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.business_plan_versions.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.business_plan_versions.belongsTo(db.ai_runs, {
      as: 'generated_by_run',
      foreignKey: {
        name: 'generated_by_runId',
      },
      constraints: false,
    });

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



    db.business_plan_versions.hasMany(db.file, {
      as: 'exports',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.business_plan_versions.getTableName(),
        belongsToColumn: 'exports',
      },
    });


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

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



  return business_plan_versions;
};


