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

const MyTischtennisUpdateHistory = sequelize.define('MyTischtennisUpdateHistory', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    allowNull: false
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'user',
      key: 'id'
    },
    onDelete: 'CASCADE'
  },
  success: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  },
  message: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  errorDetails: {
    type: DataTypes.TEXT,
    allowNull: true,
    field: 'error_details'
  },
  updatedCount: {
    type: DataTypes.INTEGER,
    allowNull: true,
    defaultValue: 0,
    field: 'updated_count'
  },
  executionTime: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: 'Execution time in milliseconds',
    field: 'execution_time'
  }
}, {
  underscored: true,
  tableName: 'my_tischtennis_update_history',
  timestamps: true,
  indexes: [
    {
      fields: ['user_id']
    },
    {
      fields: ['created_at']
    },
    {
      fields: ['success']
    }
  ]
});

export default MyTischtennisUpdateHistory;
