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

export interface ITechnicalDataSheet extends Document {
    name: string;
    manufacturer?: string;
    type?: string;
    fileId?: mongoose.Types.ObjectId;
    fileUrl: string;
    uploadDate: Date;
    solidsVolume?: number;
    density?: number;
    mixingRatio?: string;
    mixingRatioWeight?: string;
    mixingRatioVolume?: string;
    wftMin?: number;
    wftMax?: number;
    dftMin?: number;
    dftMax?: number;
    reducer?: string;
    yieldTheoretical?: number;
    dftReference?: number;
    yieldFactor?: number;
    dilution?: number;
    notes?: string;
    organizationId?: string;
    manufacturerCode?: string;
    minStock?: number;
    typicalApplication?: string;
}

const TechnicalDataSheetSchema: Schema = new Schema({
    organizationId: { type: String, index: true },
    name: { type: String, required: true },
    manufacturer: { type: String },
    manufacturerCode: { type: String },
    type: { type: String },
    minStock: { type: Number },
    typicalApplication: { type: String },
    fileId: { type: Schema.Types.ObjectId, ref: 'StoredFile' },
    fileUrl: { type: String },
    uploadDate: { type: Date, default: Date.now },
    solidsVolume: { type: Number },
    density: { type: Number },
    mixingRatio: { type: String },
    mixingRatioWeight: { type: String },
    mixingRatioVolume: { type: String },
    wftMin: { type: Number },
    wftMax: { type: Number },
    dftMin: { type: Number },
    dftMax: { type: Number },
    reducer: { type: String },
    yieldTheoretical: { type: Number },
    dftReference: { type: Number },
    yieldFactor: { type: Number },
    dilution: { type: Number },
    notes: { type: String },
}, { timestamps: true });

export default mongoose.models.TechnicalDataSheet || mongoose.model<ITechnicalDataSheet>('TechnicalDataSheet', TechnicalDataSheetSchema);
