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

name: {
        type: DataTypes.TEXT,
      
      

      },

model_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"tagging",


"embedding",


"face_recognition",


"captioning",


"moderation",


"duplicate_detection"

        ],

      },

provider: {
        type: DataTypes.TEXT,
      
      

      },

version: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"disabled"

        ],

      },

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

  ai_models.associate = (db) => {


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






























    db.ai_models.hasMany(db.ai_embeddings, {
      as: 'ai_embeddings_ai_model',
      foreignKey: {
          name: 'ai_modelId',
      },
      constraints: false,
    });


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


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



    db.ai_models.hasMany(db.ai_captions, {
      as: 'ai_captions_ai_model',
      foreignKey: {
          name: 'ai_modelId',
      },
      constraints: false,
    });








//end loop



    db.ai_models.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return ai_models;
};


