import mongoose, { Schema, Document } from 'mongoose';

export interface ISupplierDocument extends Document {
  // _id is handled by Mongoose
  name: string;
  code?: string;
  contactPerson?: string;
  phone?: string;
  email?: string;
  address?: string;
  status: 'active' | 'inactive';
  createdAt: Date;
  updatedAt: Date;
}

const supplierSchema = new Schema<ISupplierDocument>(
  {
    name: { type: String, required: true },
    code: String,
    contactPerson: String,
    phone: String,
    email: String,
    address: String,
    status: {
      type: String,
      enum: ['active', 'inactive'],
      default: 'active',
    },
  },
  {
    timestamps: true,
  }
);

supplierSchema.index({ name: 1 });
supplierSchema.index({ code: 1 });
supplierSchema.index({ status: 1 });

export const Supplier = mongoose.model<ISupplierDocument>('Supplier', supplierSchema);
