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

code: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

competency_area: {
        type: DataTypes.TEXT,
      
      

      },

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

  curriculum_standards.associate = (db) => {


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










    db.curriculum_standards.hasMany(db.skills, {
      as: 'skills_standard',
      foreignKey: {
          name: 'standardId',
      },
      constraints: false,
    });



















//end loop



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

    db.curriculum_standards.belongsTo(db.grade_levels, {
      as: 'grade_level',
      foreignKey: {
        name: 'grade_levelId',
      },
      constraints: false,
    });




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

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



  return curriculum_standards;
};


