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

forecast_name: {
        type: DataTypes.TEXT,
      
      

      },

horizon: {
        type: DataTypes.ENUM,
      
      

        values: [

"4_weeks",


"8_weeks",


"13_weeks",


"6_months",


"12_months"

        ],

      },

start_date: {
        type: DataTypes.DATE,
      
      

      },

end_date: {
        type: DataTypes.DATE,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

starting_cash: {
        type: DataTypes.DECIMAL,
      
      

      },

projected_ending_cash: {
        type: DataTypes.DECIMAL,
      
      

      },

runway_months: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"superseded"

        ],

      },

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

  forecasts.associate = (db) => {


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
















    db.forecasts.hasMany(db.forecast_scenarios, {
      as: 'forecast_scenarios_forecast',
      foreignKey: {
          name: 'forecastId',
      },
      constraints: false,
    });












//end loop



    db.forecasts.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

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




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

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



  return forecasts;
};


