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

title: {
        type: DataTypes.TEXT,
      
      

      },

summary: {
        type: DataTypes.TEXT,
      
      

      },

proposal: {
        type: DataTypes.TEXT,
      
      

      },

impact_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"systemic"

        ],

      },

cost_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high"

        ],

      },

time_horizon: {
        type: DataTypes.ENUM,
      
      

        values: [

"short_term",


"mid_term",


"long_term"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"under_review",


"published",


"rejected"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

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

  solution_proposals.associate = (db) => {


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























    db.solution_proposals.hasMany(db.votes, {
      as: 'votes_solution_proposal',
      foreignKey: {
          name: 'solution_proposalId',
      },
      constraints: false,
    });


    db.solution_proposals.hasMany(db.comments, {
      as: 'comments_solution_proposal',
      foreignKey: {
          name: 'solution_proposalId',
      },
      constraints: false,
    });









//end loop



    db.solution_proposals.belongsTo(db.problem_reports, {
      as: 'problem_report',
      foreignKey: {
        name: 'problem_reportId',
      },
      constraints: false,
    });

    db.solution_proposals.belongsTo(db.users, {
      as: 'author',
      foreignKey: {
        name: 'authorId',
      },
      constraints: false,
    });

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




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

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



  return solution_proposals;
};


