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

billing_frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"daily",


"weekly",


"monthly"

        ],

      },

rate: {
        type: DataTypes.DECIMAL,
      
      

      },

next_run_date: {
        type: DataTypes.DATE,
      
      

      },

last_run_date: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  recurring_invoice_templates.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.recurring_invoice_templates.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.recurring_invoice_templates.belongsTo(db.agreements, {
      as: 'agreement',
      foreignKey: {
        name: 'agreementId',
      },
      constraints: false,
    });




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

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



  return recurring_invoice_templates;
};


