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

/**
 * Config Model
 * Stores system configuration key-value pairs
 */
const Config = sequelize.define('Config', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
  },
  key: {
    type: DataTypes.STRING(100),
    allowNull: false,
    unique: true,
    comment: 'Configuration key',
  },
  value: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: 'Configuration value',
  },
  type: {
    type: DataTypes.ENUM('string', 'number', 'boolean', 'json', 'image'),
    defaultValue: 'string',
    allowNull: false,
    comment: 'Value type',
  },
  category: {
    type: DataTypes.STRING(50),
    defaultValue: 'general',
    allowNull: false,
    comment: 'Configuration category',
  },
  description: {
    type: DataTypes.STRING(500),
    allowNull: true,
    comment: 'Configuration description',
  },
}, {
  tableName: 'config',
  timestamps: true,
  underscored: true,
  indexes: [
    { fields: ['key'], unique: true },
    { fields: ['category'] },
  ],
});

module.exports = Config;
