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

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"internal",


"external"

        ],

      },

body: {
        type: DataTypes.TEXT,
      
      

      },

posted_at: {
        type: DataTypes.DATE,
      
      

      },

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

  activity_comments.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.activity_comments.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.users, {
      as: 'author',
      foreignKey: {
        name: 'authorId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.booking_requests, {
      as: 'booking_request',
      foreignKey: {
        name: 'booking_requestId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.reservations, {
      as: 'reservation',
      foreignKey: {
        name: 'reservationId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.service_requests, {
      as: 'service_request',
      foreignKey: {
        name: 'service_requestId',
      },
      constraints: false,
    });

    db.activity_comments.belongsTo(db.invoices, {
      as: 'invoice',
      foreignKey: {
        name: 'invoiceId',
      },
      constraints: false,
    });




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

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



  return activity_comments;
};


