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_lines = sequelize.define(
    'service_lines',
    {
      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,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"ai_ml",


"cybersecurity",


"cloud",


"hardware",


"web_mobile",


"database"

        ],

      },

pricing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"project_fixed",


"time_material",


"recurring",


"hybrid"

        ],

      },

min_price: {
        type: DataTypes.DECIMAL,
      
      

      },

max_price: {
        type: DataTypes.DECIMAL,
      
      

      },

typical_timeline: {
        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,
    },
  );

  service_lines.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_lines.hasMany(db.services, {
      as: 'services_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });








    db.service_lines.hasMany(db.deals, {
      as: 'deals_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });


    db.service_lines.hasMany(db.project_templates, {
      as: 'project_templates_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });


    db.service_lines.hasMany(db.projects, {
      as: 'projects_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });















    db.service_lines.hasMany(db.time_entries, {
      as: 'time_entries_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });



    db.service_lines.hasMany(db.contracts, {
      as: 'contracts_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });






    db.service_lines.hasMany(db.support_tickets, {
      as: 'support_tickets_service_line',
      foreignKey: {
          name: 'service_lineId',
      },
      constraints: false,
    });









//end loop



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

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




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

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



  return service_lines;
};


