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

name: {
        type: DataTypes.TEXT,
      
      

      },

billing_cycle: {
        type: DataTypes.ENUM,
      
      

        values: [

"one_time",


"monthly",


"termly",


"annual"

        ],

      },

total_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  fee_plans.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_plans.hasMany(db.invoices, {
      as: 'invoices_fee_plan',
      foreignKey: {
          name: 'fee_planId',
      },
      constraints: false,
    });









//end loop



    db.fee_plans.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

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

    db.fee_plans.belongsTo(db.grades, {
      as: 'grade',
      foreignKey: {
        name: 'gradeId',
      },
      constraints: false,
    });




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

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



  return fee_plans;
};


