import { DataTypes } from 'sequelize';
import sequelize from '../config/database.js';

const TranslationDictionary = sequelize.define('TranslationDictionary', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    validate: {
      notEmpty: true,
      len: [3, 255]
    }
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  projectId: {
    type: DataTypes.UUID,
    allowNull: false,
    references: {
      model: 'Projects',
      key: 'id'
    }
  },
  createdBy: {
    type: DataTypes.UUID,
    allowNull: false,
    references: {
      model: 'Users',
      key: 'id'
    }
  },
  status: {
    type: DataTypes.ENUM('draft', 'active', 'archived'),
    defaultValue: 'draft'
  },
  version: {
    type: DataTypes.INTEGER,
    defaultValue: 1,
    allowNull: false
  },
  metadata: {
    type: DataTypes.JSONB,
    defaultValue: {
      sourceSystem: null,
      targetSystem: null,
      coverage: 0,
      validationStatus: 'pending',
      lastValidated: null,
      tags: []
    }
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  timestamps: true,
  indexes: [
    { fields: ['projectId'] },
    { fields: ['createdBy'] },
    { fields: ['status'] },
    { fields: ['createdAt'] }
  ]
});

export default TranslationDictionary;
