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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

billing_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"per_day",


"per_rental"

        ],

      },

price: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

deductible_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  insurance_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.insurance_plans.hasMany(db.bookings, {
      as: 'bookings_insurance_plan',
      foreignKey: {
          name: 'insurance_planId',
      },
      constraints: false,
    });












//end loop



    db.insurance_plans.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.insurance_plans.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return insurance_plans;
};


