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

title: {
        type: DataTypes.TEXT,
      
      

      },

map_data_json: {
        type: DataTypes.TEXT,
      
      

      },

format: {
        type: DataTypes.ENUM,
      
      

        values: [

"json",


"mermaid",


"graphviz"

        ],

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

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

  concept_maps.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.concept_maps.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.concept_maps.belongsTo(db.sources, {
      as: 'source',
      foreignKey: {
        name: 'sourceId',
      },
      constraints: false,
    });

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




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

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



  return concept_maps;
};


