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

inquiry_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"contact_message",


"request_samples",


"get_a_quote",


"partner_with_us"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"in_progress",


"replied",


"qualified",


"closed"

        ],

      },

full_name: {
        type: DataTypes.TEXT,
      
      

      },

email: {
        type: DataTypes.TEXT,
      
      

      },

phone: {
        type: DataTypes.TEXT,
      
      

      },

company_name: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

buyer_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"roaster",


"importer",


"distributor",


"specialty_buyer",


"wholesaler",


"other"

        ],

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

target_volume_kg: {
        type: DataTypes.DECIMAL,
      
      

      },

incoterm: {
        type: DataTypes.ENUM,
      
      

        values: [

"fob",


"cif",


"cfr",


"exw",


"dap",


"other"

        ],

      },

preferred_contact_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"email",


"phone",


"whatsapp"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

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

  inquiries.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.inquiries.belongsTo(db.coffee_regions, {
      as: 'requested_region',
      foreignKey: {
        name: 'requested_regionId',
      },
      constraints: false,
    });

    db.inquiries.belongsTo(db.coffee_lots, {
      as: 'requested_lot',
      foreignKey: {
        name: 'requested_lotId',
      },
      constraints: false,
    });

    db.inquiries.belongsTo(db.users, {
      as: 'assigned_to',
      foreignKey: {
        name: 'assigned_toId',
      },
      constraints: false,
    });




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

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



  return inquiries;
};


