const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const shopSchema = new Schema({
    adminId:{
        type: Schema.Types.ObjectId,
        ref: "Admin",
        required: true
    },
    postalCode:{
        type: String,
        required: true
    },
    cookingTime:{
        type: String,
        required: true
    },
    category:{
        type: [String],
    },
    barName:{
        type: String
    },
    barDetails: {
        type: String,
    },
    shopImage:{
        type: String
    },
    workingDays:[{
        day:{
            type: String,
            enum:["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
            required: true,
        },
        isActive: {
            type: Boolean,
            default: false,
        },
        openingTime: {
            type: String,
            required: true,
        },
        closeingTime: {
            type: String,
            required: true,
        }
    }],
    latitude:{
        type: Number,
    },
    longitude: {
        type: Number
    },
    address:{
        type: String
    },
    location:{
        type:{
            type: String,
            enum: ["Point"],
        }, 
        coordinates:{
            type: [Number]
        },
        address: {
            type: String
        },
    },
    avgRating:{
        type: Number,
        default: 0
    },
    favouriteBy:[{
        type: Schema.Types.ObjectId,
        ref: "User"
    }]
});

shopSchema.index({ location: "2dsphere" });

const shopModel = mongoose.model("Shop", shopSchema);
module.exports = shopModel;