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

export interface IStore extends Document {
  name: string;
  brand: string;
  address: string;

  // city: string;
  // state: string;
  // pincode: string;

  phone: string;

  openTime: string;
  closeTime: string;

  // workingDays: {
  //   monday: boolean;
  //   tuesday: boolean;
  //   wednesday: boolean;
  //   thursday: boolean;
  //   friday: boolean;
  //   saturday: boolean;
  //   sunday: boolean;
  // };

//   coordinates: {
//     lat: number;
//     lng: number;
//   };

  isActive: boolean;

  // isFlagship: boolean;

  createdAt: Date;
  updatedAt: Date;
}

const StoreSchema = new Schema<IStore>(
  {
    name: { type: String, required: true, trim: true },

    brand: {
      type: String,
      required: false,
      default: "dulhesaheb",
      trim: true,
    },

    address: { type: String, required: true, trim: true },

    // city: { type: String, required: true, trim: true },
    // state: { type: String, required: true, trim: true },
    // pincode: { type: String, required: true, trim: true },

    phone: { type: String, required: true, trim: true },

    openTime: {
      type: String,
      required: true,
    },

    closeTime: {
      type: String,
      required: true,
    },

    // workingDays: {
    //   monday:    { type: Boolean, default: true },
    //   tuesday:   { type: Boolean, default: true },
    //   wednesday: { type: Boolean, default: true },
    //   thursday:  { type: Boolean, default: true },
    //   friday:    { type: Boolean, default: true },
    //   saturday:  { type: Boolean, default: true },
    //   sunday:    { type: Boolean, default: false },
    // },

    // coordinates: {
    //   lat: { type: Number, default: 0 },
    //   lng: { type: Number, default: 0 },
    // },

    isActive: {
      type: Boolean,
      default: true,
    },

    // isFlagship: {
    //   type: Boolean,
    //   default: false,
    // },
  },
  { timestamps: true }
);

// StoreSchema.index({ city: 1, state: 1, pincode: 1 });

StoreSchema.index({
  "coordinates.lat": 1,
  "coordinates.lng": 1,
});

export default mongoose.models.stores ||
  mongoose.model<IStore>("stores", StoreSchema);