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

service_name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

base_price: {
        type: DataTypes.DECIMAL,
      
      

      },

estimated_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  repair_services.associate = (db) => {


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









    db.repair_services.hasMany(db.order_items, {
      as: 'order_items_repair_service',
      foreignKey: {
          name: 'repair_serviceId',
      },
      constraints: false,
    });











//end loop






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

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



  return repair_services;
};


