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

profile_name: {
        type: DataTypes.TEXT,
      
      

      },

origin_country: {
        type: DataTypes.TEXT,
      
      

      },

origin_region: {
        type: DataTypes.TEXT,
      
      

      },

origin_postal_code: {
        type: DataTypes.TEXT,
      
      

      },

rules_json: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  shipping_profiles.associate = (db) => {


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




































//end loop



    db.shipping_profiles.belongsTo(db.merch_stores, {
      as: 'merch_store',
      foreignKey: {
        name: 'merch_storeId',
      },
      constraints: false,
    });

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




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

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



  return shipping_profiles;
};


