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

link_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"references",


"implements",


"specifies",


"tests"

        ],

      },

linked_at: {
        type: DataTypes.DATE,
      
      

      },

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

  story_document_links.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.story_document_links.belongsTo(db.user_stories, {
      as: 'story',
      foreignKey: {
        name: 'storyId',
      },
      constraints: false,
    });

    db.story_document_links.belongsTo(db.documents, {
      as: 'document',
      foreignKey: {
        name: 'documentId',
      },
      constraints: false,
    });

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




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

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



  return story_document_links;
};


