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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

pricing_model: {
        type: DataTypes.ENUM,
      
      

        values: [

"flat",


"hourly",


"per_room",


"per_sqft"

        ],

      },

base_price: {
        type: DataTypes.DECIMAL,
      
      

      },

hourly_rate: {
        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_catalog_items.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_catalog_items.hasMany(db.job_templates, {
      as: 'job_templates_service_catalog_item',
      foreignKey: {
          name: 'service_catalog_itemId',
      },
      constraints: false,
    });


    db.service_catalog_items.hasMany(db.jobs, {
      as: 'jobs_service_catalog_item',
      foreignKey: {
          name: 'service_catalog_itemId',
      },
      constraints: false,
    });













    db.service_catalog_items.hasMany(db.recurring_schedules, {
      as: 'recurring_schedules_service_catalog_item',
      foreignKey: {
          name: 'service_catalog_itemId',
      },
      constraints: false,
    });







//end loop



    db.service_catalog_items.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

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




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

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



  return service_catalog_items;
};


