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

source_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"journal",


"government",


"education",


"organization",


"dataset",


"book",


"transcript",


"other"

        ],

      },

source_title: {
        type: DataTypes.TEXT,
      
      

      },

source_url: {
        type: DataTypes.TEXT,
      
      

      },

publisher: {
        type: DataTypes.TEXT,
      
      

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

quote_excerpt: {
        type: DataTypes.TEXT,
      
      

      },

doi_or_identifier: {
        type: DataTypes.TEXT,
      
      

      },

credibility_grade: {
        type: DataTypes.ENUM,
      
      

        values: [

"a",


"b",


"c",


"d",


"unknown"

        ],

      },

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

  citations.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.citations.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return citations;
};


