import {Schema}from'mongoose';import {commonModeSchemaOptions,addIdVirtualFields}from'@common-stack/store-mongo';const stateModelSchema = new Schema({
    name: { type: Schema.Types.String, required: true, maxlength: 150 },
    country: { type: Schema.Types.String, ref: 'countries', onDelete: 'cascade' },
    location: {
        type: {
            type: Schema.Types.String,
            default: 'Point',
            enum: ['Point'], // 'location.type' must be 'Point'
        },
        coordinates: {
            type: [Schema.Types.Number],
            required: true,
        },
    },
    _id: { type: Schema.Types.String, required: true, unique: true },
}, {
    ...commonModeSchemaOptions,
    _id: false,
});
stateModelSchema.index({ name: 1, country: 1 }, { unique: true });
stateModelSchema.index({ _id: 1, country: 1 }, { unique: true });
stateModelSchema.index({ location: '2dsphere' });
addIdVirtualFields(stateModelSchema);
const StateModelFunc = (db) => db.model('states', stateModelSchema);export{StateModelFunc};