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

const User = sequelize.define('users', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  username: { type: DataTypes.STRING(50), unique: true, allowNull: false },
  email: { type: DataTypes.STRING(100), unique: true, allowNull: false },
  password_hash: { type: DataTypes.STRING(255), allowNull: false },
  full_name: { type: DataTypes.STRING(100), allowNull: false },
  phone: { type: DataTypes.STRING(20) },
  role: { type: DataTypes.ENUM('admin', 'manager', 'staff'), defaultValue: 'staff' },
  is_active: { type: DataTypes.BOOLEAN, defaultValue: true },
  block_reason: { type: DataTypes.STRING(500) },
  last_login: { type: DataTypes.DATE },
  reset_password_token: { type: DataTypes.STRING(255) },
  reset_password_expires: { type: DataTypes.DATE },
}, {
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
});

module.exports = User;
