import mongoose from 'mongoose';
import { generateId } from '../../utils.js';
const { Schema } = mongoose;

const courierServiceSchema = new mongoose.Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: { required: true, type: String },
    courier: { type: Schema.Types.ObjectId, ref: 'courier', required: true },
    active: { required: true, type: Boolean },
    tracked: { required: true, type: Boolean },
    deliveryTime: { required: true, type: Number },
    website: { required: false, type: String },
  },
  { timestamps: true }
);

courierServiceSchema.virtual('id').get(function () {
  return this._id;
});

courierServiceSchema.set('toJSON', { virtuals: true });

export const courierServiceModel = mongoose.model('courierService', courierServiceSchema);
