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

const TaxiLevelStats = sequelize.define('TaxiLevelStats', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  level: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  bestScore: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  bestMoney: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  bestPassengersDelivered: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  timesPlayed: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  completed: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  },
  playTime: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: 'Play time in seconds'
  },
  // createdAt/updatedAt via timestamps
}, {
  tableName: 'taxi_level_stat',
  schema: 'taxi',
  timestamps: true,
  underscored: true,
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'level']
    },
    {
      fields: ['level']
    },
    {
      fields: ['best_score']
    },
    {
      fields: ['completed']
    }
  ]
});

export default TaxiLevelStats;
