import {__decorate,__param,__metadata}from'tslib';import'@cdm-logger/core';import {injectable,inject,optional}from'inversify';import {BaseMongoRepository}from'@common-stack/store-mongo';import mongoose from'mongoose';import'../models/city.js';import'../models/country.js';import {StateModelFunc}from'../models/state.js';let StateRepository = class StateRepository extends BaseMongoRepository {
  constructor(db, logger, options) {
    super(StateModelFunc, db, logger, options);
    this.logger = logger.child({
      className: 'StateRepository'
    });
  }
  async findByCountry(country) {
    this.logger.trace('findByCountry with params (%j)', {
      country
    });
    const result = await this.model.find({
      country
    }).exec();
    return result || [];
  }
  async findByName(name) {
    this.logger.trace('findByName with params (%j)', {
      name
    });
    const result = await this.model.findOne({
      name: {
        $regex: name,
        $options: 'i'
      }
    }).exec();
    return result || null;
  }
  async findByLocation(longitude, latitude, radiusInKm) {
    this.logger.trace('findByLocation with params (%j)', {
      longitude,
      latitude,
      radiusInKm
    });
    const result = await this.model.find({
      location: {
        $near: {
          $geometry: {
            type: 'Point',
            coordinates: [longitude, latitude]
          },
          $maxDistance: radiusInKm * 1000 // Convert km to meters
        }
      }
    }).exec();
    return result || [];
  }
};
StateRepository = __decorate([injectable(), __param(0, inject('MongoDBConnection')), __param(1, inject('Logger')), __param(2, inject('MongoOptions')), __param(2, optional()), __metadata("design:paramtypes", [mongoose.Connection, Object, Object])], StateRepository);export{StateRepository};//# sourceMappingURL=state-repository.js.map
