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

name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

pricing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"flat",


"per_unit",


"starting_at"

        ],

      },

unit_price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  service_add_ons.associate = (db) => {


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












    db.service_add_ons.hasMany(db.service_request_add_ons, {
      as: 'service_request_add_ons_service_add_on',
      foreignKey: {
          name: 'service_add_onId',
      },
      constraints: false,
    });





















//end loop



    db.service_add_ons.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return service_add_ons;
};


