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

name: {
        type: DataTypes.TEXT,
      
      

      },

priority: {
        type: DataTypes.ENUM,
      
      

        values: [

"p1",


"p2",


"p3",


"p4"

        ],

      },

first_response_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

resolution_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  support_slas.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity






































    db.support_slas.hasMany(db.support_tickets, {
      as: 'support_tickets_sla',
      foreignKey: {
          name: 'slaId',
      },
      constraints: false,
    });









//end loop



    db.support_slas.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

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




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

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



  return support_slas;
};


