import mongoose from 'mongoose';

// --- Category ---
const CategorySchema = new mongoose.Schema({
    name: { type: String, required: true },
    icon: String,
    color: String,
});

export const Category = mongoose.models.Category || mongoose.model('Category', CategorySchema);

// --- Product ---
const ProductSchema = new mongoose.Schema({
    name: { type: String, required: true },
    price: { type: Number, required: true },
    category: { type: mongoose.Schema.Types.ObjectId, ref: 'Category' },
    image: String,
    available: { type: Boolean, default: true },
    isAddon: { type: Boolean, default: false },
});

export const Product = mongoose.models.Product || mongoose.model('Product', ProductSchema);

// --- Floor ---
const FloorSchema = new mongoose.Schema({
    id: { type: Number, required: true, unique: true }, // Using number ID to match frontend for now, or could use auto-generated _id
    name: { type: String, required: true },
});

export const Floor = mongoose.models.Floor || mongoose.model('Floor', FloorSchema);

// --- Table ---
const TableSchema = new mongoose.Schema({
    id: { type: Number, required: true, unique: true }, // Custom ID to match frontend
    name: { type: String, required: true },
    seats: { type: Number, default: 4 },
    floorId: { type: Number, required: true },
    status: { type: String, enum: ['available', 'occupied', 'reserved'], default: 'available' },
    x: { type: Number, default: 0 },
    y: { type: Number, default: 0 },
    width: Number,
    height: Number,
    shape: { type: String, enum: ['rect', 'circle', 'square'], default: 'circle' },
    currentOrderId: { type: mongoose.Schema.Types.ObjectId, ref: 'Order' },
});

export const Table = mongoose.models.Table || mongoose.model('Table', TableSchema);

// Order model moved to Order.ts
