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

executive_summary: {
        type: DataTypes.TEXT,
      
      

      },

truth_score_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

verification_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"verified",


"partially_verified",


"unverified",


"conflicting"

        ],

      },

ready_to_cite_text: {
        type: DataTypes.TEXT,
      
      

      },

neutral_perspective: {
        type: DataTypes.TEXT,
      
      

      },

pro_perspective: {
        type: DataTypes.TEXT,
      
      

      },

contra_perspective: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  facta_answers.associate = (db) => {

    db.facta_answers.belongsToMany(db.citations, {
      as: 'citations',
      foreignKey: {
        name: 'facta_answers_citationsId',
      },
      constraints: false,
      through: 'facta_answersCitationsCitations',
    });

    db.facta_answers.belongsToMany(db.citations, {
      as: 'citations_filter',
      foreignKey: {
        name: 'facta_answers_citationsId',
      },
      constraints: false,
      through: 'facta_answersCitationsCitations',
    });


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












































//end loop



    db.facta_answers.belongsTo(db.facta_queries, {
      as: 'facta_query',
      foreignKey: {
        name: 'facta_queryId',
      },
      constraints: false,
    });

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




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

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



  return facta_answers;
};


