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

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"internal",


"public"

        ],

      },

body: {
        type: DataTypes.TEXT,
      
      

      },

posted_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.ticket_comments.belongsTo(db.support_tickets, {
      as: 'ticket',
      foreignKey: {
        name: 'ticketId',
      },
      constraints: false,
    });

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

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



    db.ticket_comments.hasMany(db.file, {
      as: 'attachments',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.ticket_comments.getTableName(),
        belongsToColumn: 'attachments',
      },
    });


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

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



  return ticket_comments;
};


