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

const UserProgress = sequelize.define('UserProgress', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.STRING(255),
    allowNull: false
  },
  campaignId: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  totalScore: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  totalStars: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  levelsCompleted: {
    type: DataTypes.INTEGER,
    defaultValue: 0
  },
  currentLevel: {
    type: DataTypes.INTEGER,
    defaultValue: 1
  },
  isCompleted: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  lastPlayed: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'match3_user_progress',
  schema: 'match3',
  timestamps: true,
  underscored: true,  // WICHTIG: Alle Datenbankfelder im snake_case Format
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'campaign_id']  // WICHTIG: Bei underscored: true müssen snake_case Namen verwendet werden
    }
  ]
});

export default UserProgress;
