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

const taxRateSchema = new mongoose.Schema(
  {
    _reference: { type: String, default: () => generateId()() },
    name: { required: true, type: String },
    rate: { required: true, type: Number },
    rateType: { required: true, type: String, enum: ['percentage', 'fixed'] },
    active: { required: true, type: Boolean, default: true },
    description: { required: false, type: String },
    country: { required: false, type: String },
    effectiveFrom: { required: false, type: Date },
    effectiveTo: { required: false, type: Date },
  },
  { timestamps: true }
);

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

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

export const taxRateModel = mongoose.model('taxRate', taxRateSchema);
