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

gradebook_name: {
        type: DataTypes.TEXT,
      
      

      },

term: {
        type: DataTypes.ENUM,
      
      

        values: [

"q1",


"q2",


"q3",


"q4",


"semester1",


"semester2",


"final"

        ],

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

is_published: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  gradebooks.associate = (db) => {


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


















    db.gradebooks.hasMany(db.gradebook_columns, {
      as: 'gradebook_columns_gradebook',
      foreignKey: {
          name: 'gradebookId',
      },
      constraints: false,
    });



    db.gradebooks.hasMany(db.adviser_reports, {
      as: 'adviser_reports_gradebook',
      foreignKey: {
          name: 'gradebookId',
      },
      constraints: false,
    });












//end loop



    db.gradebooks.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });

    db.gradebooks.belongsTo(db.classrooms, {
      as: 'classroom',
      foreignKey: {
        name: 'classroomId',
      },
      constraints: false,
    });

    db.gradebooks.belongsTo(db.subjects, {
      as: 'subject',
      foreignKey: {
        name: 'subjectId',
      },
      constraints: false,
    });

    db.gradebooks.belongsTo(db.users, {
      as: 'owner_teacher',
      foreignKey: {
        name: 'owner_teacherId',
      },
      constraints: false,
    });




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

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



  return gradebooks;
};


