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

asset_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"glb",


"gltf",


"usdz",


"texture_set",


"other"

        ],

      },

viewer_hint_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_3d_assets.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.stone_3d_assets.belongsTo(db.stones, {
      as: 'stone',
      foreignKey: {
        name: 'stoneId',
      },
      constraints: false,
    });



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

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


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

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



  return stone_3d_assets;
};


