const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

/**
 * Notification Model
 * Represents system notifications to users
 */
const Notification = sequelize.define('Notification', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
  },
  userId: {
    type: DataTypes.UUID,
    allowNull: false,
    field: 'user_id',
    references: {
      model: 'user',
      key: 'id',
    },
  },
  type: {
    type: DataTypes.ENUM('system', 'activity', 'service'),
    allowNull: false,
  },
  titleZh: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_zh',
  },
  titleEn: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_en',
  },
  titleEs: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'title_es',
  },
  contentZh: {
    type: DataTypes.TEXT,
    allowNull: false,
    field: 'content_zh',
  },
  contentEn: {
    type: DataTypes.TEXT,
    allowNull: false,
    field: 'content_en',
  },
  contentEs: {
    type: DataTypes.TEXT,
    allowNull: false,
    field: 'content_es',
  },
  isRead: {
    type: DataTypes.BOOLEAN,
    defaultValue: false,
    allowNull: false,
    field: 'is_read',
  },
  readAt: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'read_at',
  },
}, {
  tableName: 'notification',
  timestamps: true,
  underscored: true,
  indexes: [
    { fields: ['user_id'] },
    { fields: ['type'] },
    { fields: ['is_read'] },
  ],
});

module.exports = Notification;
