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

/**
 * Translation Model
 * Stores translations for dynamic content
 */
const Translation = sequelize.define('Translation', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
  },
  key: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: 'Translation key identifier',
  },
  category: {
    type: DataTypes.STRING(100),
    allowNull: false,
    defaultValue: 'general',
    comment: 'Translation category (e.g., notification, service, system)',
  },
  language: {
    type: DataTypes.ENUM('zh', 'en', 'pt'),
    allowNull: false,
    comment: 'Language code',
  },
  value: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: 'Translated text value',
  },
  description: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: 'Description of what this translation is for',
  },
}, {
  tableName: 'translation',
  timestamps: true,
  underscored: true,
  indexes: [
    { 
      unique: true,
      fields: ['key', 'language'],
      name: 'translation_key_language_unique',
    },
    { fields: ['category'] },
    { fields: ['language'] },
  ],
});

module.exports = Translation;
