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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"invoice",


"receipt",


"credit_note",


"debit_note"

        ],

      },

submission_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"submitted",


"accepted",


"rejected",


"failed",


"cancelled"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

last_attempt_at: {
        type: DataTypes.DATE,
      
      

      },

attempt_count: {
        type: DataTypes.INTEGER,
      
      

      },

request_payload_json: {
        type: DataTypes.TEXT,
      
      

      },

response_payload_json: {
        type: DataTypes.TEXT,
      
      

      },

efris_invoice_no: {
        type: DataTypes.TEXT,
      
      

      },

efris_receipt_no: {
        type: DataTypes.TEXT,
      
      

      },

verification_code: {
        type: DataTypes.TEXT,
      
      

      },

qr_code_data: {
        type: DataTypes.TEXT,
      
      

      },

error_code: {
        type: DataTypes.TEXT,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  efris_submissions.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.efris_submissions.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.efris_submissions.belongsTo(db.invoices, {
      as: 'invoice',
      foreignKey: {
        name: 'invoiceId',
      },
      constraints: false,
    });

    db.efris_submissions.belongsTo(db.receipts, {
      as: 'receipt',
      foreignKey: {
        name: 'receiptId',
      },
      constraints: false,
    });




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

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



  return efris_submissions;
};


