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

id_document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"chile_cedula",


"passport",


"dni",


"rut_other",


"other"

        ],

      },

quality_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"acceptable",


"rejected"

        ],

      },

quality_notes: {
        type: DataTypes.TEXT,
      
      

      },

match_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  id_verification_artifacts.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.id_verification_artifacts.belongsTo(db.authentication_attempts, {
      as: 'authentication_attempt',
      foreignKey: {
        name: 'authentication_attemptId',
      },
      constraints: false,
    });

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



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

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


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

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



  return id_verification_artifacts;
};


