import mongoose, { Schema, Document } from 'mongoose';

export interface IPart extends Document {
    projectId?: mongoose.Types.ObjectId;
    description: string;
    dimensions?: string | null;
    weight?: number | null;
    type?: string | null;
    area?: number | null;
    complexity?: number | null;
    quantity: number;
    notes?: string | null;
    organizationId?: string;
}

const PartSchema: Schema = new Schema({
    organizationId: { type: String, index: true },
    projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: false },
    description: { type: String, required: true },
    dimensions: { type: String },
    weight: { type: Number },
    type: { type: String },
    area: { type: Number },
    complexity: { type: Number },
    quantity: { type: Number, required: true, default: 1 },
    notes: { type: String },
});

export default mongoose.models.Part || mongoose.model<IPart>('Part', PartSchema);
