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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"driver_license",


"passport",


"id_card",


"insurance",


"other"

        ],

      },

document_number: {
        type: DataTypes.TEXT,
      
      

      },

issued_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

verification_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"verified",


"rejected"

        ],

      },

verification_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  customer_documents.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.customer_documents.belongsTo(db.users, {
      as: 'customer',
      foreignKey: {
        name: 'customerId',
      },
      constraints: false,
    });

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



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


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

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



  return customer_documents;
};


