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

relationship: {
        type: DataTypes.ENUM,
      
      

        values: [

"ayah",


"ibu",


"wali"

        ],

      },

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

      },

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

  parent_student_links.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.parent_student_links.belongsTo(db.users, {
      as: 'parent_user',
      foreignKey: {
        name: 'parent_userId',
      },
      constraints: false,
    });

    db.parent_student_links.belongsTo(db.students, {
      as: 'student',
      foreignKey: {
        name: 'studentId',
      },
      constraints: false,
    });

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




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

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



  return parent_student_links;
};


