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

name: {
        type: DataTypes.TEXT,
      
      

      },

canvas_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"archived"

        ],

      },

last_edited_at: {
        type: DataTypes.DATE,
      
      

      },

snapshot_uri: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  canvas_documents.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity





























    db.canvas_documents.hasMany(db.canvas_events, {
      as: 'canvas_events_canvas_document',
      foreignKey: {
          name: 'canvas_documentId',
      },
      constraints: false,
    });



























//end loop



    db.canvas_documents.belongsTo(db.rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });

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




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

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



  return canvas_documents;
};


