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

installation_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"installed",


"paused",


"disabled",


"uninstalled"

        ],

      },

installed_at: {
        type: DataTypes.DATE,
      
      

      },

disabled_at: {
        type: DataTypes.DATE,
      
      

      },

disable_reason: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  app_installations.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.app_installations.belongsTo(db.marketplace_apps, {
      as: 'marketplace_app',
      foreignKey: {
        name: 'marketplace_appId',
      },
      constraints: false,
    });

    db.app_installations.belongsTo(db.teams, {
      as: 'team',
      foreignKey: {
        name: 'teamId',
      },
      constraints: false,
    });

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




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

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



  return app_installations;
};


