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

variant_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"slab",


"tile",


"stair",


"countertop",


"custom"

        ],

      },

sku: {
        type: DataTypes.TEXT,
      
      

      },

length_mm: {
        type: DataTypes.DECIMAL,
      
      

      },

width_mm: {
        type: DataTypes.DECIMAL,
      
      

      },

thickness_mm: {
        type: DataTypes.DECIMAL,
      
      

      },

weight_kg: {
        type: DataTypes.DECIMAL,
      
      

      },

availability_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"in_stock",


"made_to_order",


"out_of_stock",


"discontinued"

        ],

      },

base_price: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  stone_variants.associate = (db) => {


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

























    db.stone_variants.hasMany(db.quote_items, {
      as: 'quote_items_stone_variant',
      foreignKey: {
          name: 'stone_variantId',
      },
      constraints: false,
    });






//end loop



    db.stone_variants.belongsTo(db.stones, {
      as: 'stone',
      foreignKey: {
        name: 'stoneId',
      },
      constraints: false,
    });



    db.stone_variants.hasMany(db.file, {
      as: 'images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.stone_variants.getTableName(),
        belongsToColumn: 'images',
      },
    });


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

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



  return stone_variants;
};


