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

const vendorSchema = new mongoose.Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: { required: true, type: String },
    website: { required: false, type: String },
    email: { required: false, type: String },
    phone: { required: false, type: String },
    contact: { required: false, type: String },
    country: { required: false, type: String },
  },
  { timestamps: true }
);

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

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

export const vendorModel = mongoose.model('vendor', vendorSchema);
