import mongoose from 'mongoose';

const locationSchema = new mongoose.Schema(
  {
    lat: { type: Number, required: true },
    lng: { type: Number, required: true },
  },
  { _id: false },
);

const storeSchema = new mongoose.Schema(
  {
    householdId: { type: String, required: true },
    name: { type: String, required: true },
    address: { type: String },
    location: { type: locationSchema },
    url: { type: String },
    notes: { type: String },
    tags: { type: [String], default: [] },
    isActive: { type: Boolean, required: true, default: true },
    createdBy: { type: String, required: true },
  },
  { timestamps: true },
);

storeSchema.index({ householdId: 1, name: 1 });
storeSchema.index({ householdId: 1, tags: 1 });

export const StoreModel = mongoose.model('Store', storeSchema);
export type StoreDocument = mongoose.InferSchemaType<typeof storeSchema> & {
  _id: mongoose.Types.ObjectId;
};
