// models/Ticket.js
const mongoose = require('mongoose');

const ticketSchema = new mongoose.Schema({
  title:         { type: String, required: true, trim: true },
  description:   { type: String, required: true, trim: true },
  phase:         { type: String, enum: ['open','testing','development','production'], default: 'open' },
  priority:      { type: String, enum: ['high','medium','low'], default: 'medium' },
  dailyRate:     {
                   type: Number,
                   required: true,
                   min: 0,
                   default: 0
                 },
  estimatedDays: {
                   type: Number,
                   required: true,
                   min: 0,
                   default: 0,
                   validate: {
                     validator: Number.isInteger,
                     message: '{VALUE} is not an integer value'
                   }
                 },
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  }
}, {
  timestamps: true
});

module.exports = mongoose.model('Ticket', ticketSchema);