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

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

report_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"reviewed",


"approved",


"rejected"

        ],

      },

summary_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  adviser_reports.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.adviser_reports.belongsTo(db.gradebooks, {
      as: 'gradebook',
      foreignKey: {
        name: 'gradebookId',
      },
      constraints: false,
    });

    db.adviser_reports.belongsTo(db.users, {
      as: 'adviser_teacher',
      foreignKey: {
        name: 'adviser_teacherId',
      },
      constraints: false,
    });

    db.adviser_reports.belongsTo(db.users, {
      as: 'submitted_by_teacher',
      foreignKey: {
        name: 'submitted_by_teacherId',
      },
      constraints: false,
    });

    db.adviser_reports.belongsTo(db.schools, {
      as: 'schools',
      foreignKey: {
        name: 'schoolsId',
      },
      constraints: false,
    });



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


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

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



  return adviser_reports;
};


