const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const TicketMessage = sequelize.define(
    'TicketMessage',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      ticketId: {
        type: DataTypes.UUID,
        allowNull: false,
        field: 'ticket_id',
      },
      senderId: {
        type: DataTypes.UUID,
        allowNull: false,
        field: 'sender_id',
      },
      senderType: {
        type: DataTypes.ENUM('user', 'support', 'system'),
        defaultValue: 'user',
        allowNull: false,
        field: 'sender_type',
      },
      senderName: {
        type: DataTypes.STRING(150),
        allowNull: true,
        field: 'sender_name',
      },
      message: {
        type: DataTypes.TEXT,
        allowNull: false,
      },
      attachments: {
        type: DataTypes.JSON,
        defaultValue: [],
      },
      isInternal: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
        field: 'is_internal',
      },
    },
    {
      tableName: 'ticket_messages',
      underscored: true,
      timestamps: true,
    }
  );

 

  return TicketMessage;
};
