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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"linkedin",


"github",


"reddit",


"other_ai_platform"

        ],

      },

handle: {
        type: DataTypes.TEXT,
      
      

      },

profile_url: {
        type: DataTypes.TEXT,
      
      

      },

access_token_hint: {
        type: DataTypes.TEXT,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

connected_at: {
        type: DataTypes.DATE,
      
      

      },

last_synced_at: {
        type: DataTypes.DATE,
      
      

      },

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

  external_accounts.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.external_accounts.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return external_accounts;
};


