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

export interface IProduct {
	category: Types.ObjectId;
	location: Types.ObjectId;
	name: string;
	description?: string;
	image?: File;
}

export interface IProductModel extends IProduct, Document {}

const ProductSchema: Schema = new Schema(
	{
		category: {
			type: Schema.Types.ObjectId,
			ref: 'Category',
			required: true,
		},
		location: {
			type: Schema.Types.ObjectId,
			ref: 'Location',
			required: true,
		},
		name: {
			type: String,
			required: true,
		},
		description: {
			type: String,
		},
		image: {
			data: Buffer,
			contentType: String,
		},
	},
	{versionKey: false}
);

export default mongoose.model<IProductModel>('Product', ProductSchema);
