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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"ready",


"failed"

        ],

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  selfie_references.associate = (db) => {


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

































    db.selfie_references.hasMany(db.face_matches, {
      as: 'face_matches_selfie_reference',
      foreignKey: {
          name: 'selfie_referenceId',
      },
      constraints: false,
    });









//end loop



    db.selfie_references.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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

    db.selfie_references.belongsTo(db.ai_embeddings, {
      as: 'selfie_embedding',
      foreignKey: {
        name: 'selfie_embeddingId',
      },
      constraints: false,
    });

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



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


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

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



  return selfie_references;
};


