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

bbox_x: {
        type: DataTypes.DECIMAL,
      
      

      },

bbox_y: {
        type: DataTypes.DECIMAL,
      
      

      },

bbox_width: {
        type: DataTypes.DECIMAL,
      
      

      },

bbox_height: {
        type: DataTypes.DECIMAL,
      
      

      },

confidence: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  face_detections.associate = (db) => {


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

































    db.face_detections.hasMany(db.face_matches, {
      as: 'face_matches_face_detection',
      foreignKey: {
          name: 'face_detectionId',
      },
      constraints: false,
    });









//end loop



    db.face_detections.belongsTo(db.media_items, {
      as: 'media_item',
      foreignKey: {
        name: 'media_itemId',
      },
      constraints: false,
    });

    db.face_detections.belongsTo(db.ai_models, {
      as: 'ai_model',
      foreignKey: {
        name: 'ai_modelId',
      },
      constraints: false,
    });

    db.face_detections.belongsTo(db.ai_embeddings, {
      as: 'face_embedding',
      foreignKey: {
        name: 'face_embeddingId',
      },
      constraints: false,
    });

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




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

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



  return face_detections;
};


