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

external_event_key: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

location: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"tentative",


"confirmed",


"canceled"

        ],

      },

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

  calendar_events.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.calendar_events.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.calendar_events.belongsTo(db.integrations, {
      as: 'integration',
      foreignKey: {
        name: 'integrationId',
      },
      constraints: false,
    });

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




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

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



  return calendar_events;
};


