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

fee_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"spp_bulanan",


"pendaftaran"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

minimum_down_payment: {
        type: DataTypes.DECIMAL,
      
      

      },

max_installments: {
        type: DataTypes.INTEGER,
      
      

      },

installment_deadline: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  fee_definitions.associate = (db) => {


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


























    db.fee_definitions.hasMany(db.billing_items, {
      as: 'billing_items_fee_definition',
      foreignKey: {
          name: 'fee_definitionId',
      },
      constraints: false,
    });





//end loop



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

    db.fee_definitions.belongsTo(db.academic_years, {
      as: 'academic_year',
      foreignKey: {
        name: 'academic_yearId',
      },
      constraints: false,
    });

    db.fee_definitions.belongsTo(db.education_levels, {
      as: 'education_level',
      foreignKey: {
        name: 'education_levelId',
      },
      constraints: false,
    });

    db.fee_definitions.belongsTo(db.classes, {
      as: 'class',
      foreignKey: {
        name: 'classId',
      },
      constraints: false,
    });




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

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



  return fee_definitions;
};


