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

name: {
        type: DataTypes.TEXT,
      
      

      },

frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"weekly",


"biweekly",


"monthly"

        ],

      },

interval_count: {
        type: DataTypes.INTEGER,
      
      

      },

day_of_week: {
        type: DataTypes.ENUM,
      
      

        values: [

"mon",


"tue",


"wed",


"thu",


"fri",


"sat",


"sun"

        ],

      },

day_of_month: {
        type: DataTypes.INTEGER,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

is_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,
    },
  );

  recurring_schedules.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_schedules.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.recurring_schedules.belongsTo(db.customers, {
      as: 'customer',
      foreignKey: {
        name: 'customerId',
      },
      constraints: false,
    });

    db.recurring_schedules.belongsTo(db.properties, {
      as: 'property',
      foreignKey: {
        name: 'propertyId',
      },
      constraints: false,
    });

    db.recurring_schedules.belongsTo(db.service_catalog_items, {
      as: 'service_catalog_item',
      foreignKey: {
        name: 'service_catalog_itemId',
      },
      constraints: false,
    });

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




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

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



  return recurring_schedules;
};


