const mongoose = require('mongoose');

const TWebDisponibileSchema = new mongoose.Schema({
  Progressivo: {
    type: mongoose.Schema.Types.Long || Number, // Usa 'mongoose-long' se vuoi long int
    required: true,
    unique: true,
  },
  Codice: {
    type: String,
    maxlength: 50,
    required: true,
    index: true, // usato nei lookup e nei match
  },
  QtaDisponibile: {
    type: mongoose.Decimal128,
    default: 0,
  },
  Giac: {
    type: mongoose.Decimal128,
    default: 0,
  },
  DataOra: {
    type: Date,
    default: Date.now,
    index: true, // per ordinamento
  },
  Enabled: {
    type: Boolean,
    default: true,
  },
  DataOraSito: {
    type: Date,
  },
  Ean13: {
    type: String,
    maxlength: 20,
  },
  QtaDisponibileOld: {
    type: Number,
    default: 0,
  },
}, {
  collection: 't_web_disponibiles', 
  timestamps: false,
});

module.exports = mongoose.model('TWebDisponibile', TWebDisponibileSchema);

module.exports.createIndexes()
  .then(() => { })
  .catch((err) => { throw err; });
