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,
      },

event_title: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

start_at: {
        type: DataTypes.DATE,
      
      

      },

end_at: {
        type: DataTypes.DATE,
      
      

      },

color: {
        type: DataTypes.ENUM,
      
      

        values: [

"red",


"orange",


"yellow",


"green",


"blue",


"purple",


"gray"

        ],

      },

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

      },

google_calendar_event_key: {
        type: DataTypes.TEXT,
      
      

      },

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

    db.calendar_events.belongsTo(db.company_compliances, {
      as: 'related_compliance',
      foreignKey: {
        name: 'related_complianceId',
      },
      constraints: false,
    });

    db.calendar_events.belongsTo(db.tasks, {
      as: 'related_task',
      foreignKey: {
        name: 'related_taskId',
      },
      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;
};


