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

san_number: {
        type: DataTypes.TEXT,
      
      

      },

acceptance_date: {
        type: DataTypes.DATE,
      
      

      },

deliverable_checklist: {
        type: DataTypes.TEXT,
      
      

      },

acceptance_criteria: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"submitted",


"accepted",


"rejected"

        ],

      },

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

  service_acceptance_notes.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.service_acceptance_notes.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.service_acceptance_notes.belongsTo(db.purchase_orders, {
      as: 'purchase_order',
      foreignKey: {
        name: 'purchase_orderId',
      },
      constraints: false,
    });

    db.service_acceptance_notes.belongsTo(db.users, {
      as: 'accepted_by',
      foreignKey: {
        name: 'accepted_byId',
      },
      constraints: false,
    });

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



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


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

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



  return service_acceptance_notes;
};


