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

type: {
        type: DataTypes.ENUM,
      
      

        values: [

"TRADE_REGISTER_EXTRACT",


"VAT_CERTIFICATE",


"INSURANCE_POLICY",


"EU_LICENSE_COPY",


"ADR_COMPANY_CERT",


"GENERAL_TERMS",


"DATA_PROCESSING_AGREEMENT",


"OTHER"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  company_documents.associate = (db) => {


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












    db.company_documents.hasMany(db.company_document_versions, {
      as: 'company_document_versions_document',
      foreignKey: {
          name: 'documentId',
      },
      constraints: false,
    });




































//end loop



    db.company_documents.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.company_documents.belongsTo(db.company_document_versions, {
      as: 'current_version',
      foreignKey: {
        name: 'current_versionId',
      },
      constraints: false,
    });




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

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



  return company_documents;
};


