text: const mongoose = require('mongoose');
  const geocoder = require('../utils/geocoder');
  
  const StoreSchema = new mongoose.Schema({
    storeId: {
      type: String,
      required: [true, 'Please add a Barber ID'],
      unique: true,
      trim: true,
      maxLength: [10, 'Barber ID must be less than ten characters']
    },
    address: {
      type: String,
      required: [true, 'Please add an address']
    },
    location: {
      type: {
        type: String, // Don't do `{ location: { type: String } }`
        enum: ['Point'], // 'location.type' must be 'Point'
      },
      coordinates: {
        type: [Number],
        index: '2dsphere'
      },
      formattedAddress: String
    },
    createdAT: {
      type: Date,
      default: Date.now
    }
  });
  
  // Geocode and create location
  StoreSchema.pre('save', async function(next) {
    const loc = await geocoder.geocode(this.address);
    this.location = {
      type: 'Point',
      coordinates: [loc[0].longitude, loc[0].latitude],
      formattedAddress: loc[0].formattedAddress
    }
  
    // Do not save address
    this.address = undefined;
    next();
  });
  
  module.exports = mongoose.model('Store', StoreSchema);
  