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

submission_name: {
        type: DataTypes.TEXT,
      
      

      },

jurisdiction: {
        type: DataTypes.ENUM,
      
      

        values: [

"eu_mdr",


"us_fda",


"uk_mhra",


"other"

        ],

      },

submission_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"technical_documentation",


"cer",


"pms_report",


"psur",


"vigilance",


"510k",


"pma",


"de_novo",


"registration_listing",


"other"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"in_review",


"submitted",


"questions_received",


"accepted",


"rejected",


"closed"

        ],

      },

planned_submission_at: {
        type: DataTypes.DATE,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

decision_at: {
        type: DataTypes.DATE,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  regulatory_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.regulatory_submissions.belongsTo(db.products, {
      as: 'product',
      foreignKey: {
        name: 'productId',
      },
      constraints: false,
    });

    db.regulatory_submissions.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });



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


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

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



  return regulatory_submissions;
};


