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

name_fr: {
        type: DataTypes.TEXT,
      
      

      },

name_en: {
        type: DataTypes.TEXT,
      
      

      },

description_fr: {
        type: DataTypes.TEXT,
      
      

      },

description_en: {
        type: DataTypes.TEXT,
      
      

      },

deliverables: {
        type: DataTypes.TEXT,
      
      

      },

pricing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"project_fixed",


"time_material",


"recurring",


"hybrid"

        ],

      },

min_price: {
        type: DataTypes.DECIMAL,
      
      

      },

max_price: {
        type: DataTypes.DECIMAL,
      
      

      },

typical_duration_weeks: {
        type: DataTypes.INTEGER,
      
      

      },

required_skills: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  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.services.hasMany(db.leads, {
      as: 'leads_service_interest',
      foreignKey: {
          name: 'service_interestId',
      },
      constraints: false,
    });

































//end loop



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

    db.services.belongsTo(db.service_lines, {
      as: 'service_line',
      foreignKey: {
        name: 'service_lineId',
      },
      constraints: false,
    });

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




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

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



  return services;
};


