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 {CityModelFunc}from'../models/city.js';import'../models/country.js';import'../models/state.js';let CityRepository = class CityRepository extends BaseMongoRepository {
  constructor(db, logger, options) {
    super(CityModelFunc, db, logger, options);
    this.logger = logger.child({
      className: 'CityRepository'
    });
  }
  async findByState(state) {
    this.logger.trace('findByState with params (%j)', {
      state
    });
    const result = await this.model.find({
      state
    }).exec();
    return result || [];
  }
  async findByName(name) {
    this.logger.trace('findByName with params (%j)', {
      name
    });
    const result = await this.model.find({
      name: {
        $regex: name,
        $options: 'i'
      }
    }).exec();
    return result || [];
  }
  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 || [];
  }
};
CityRepository = __decorate([injectable(), __param(0, inject('MongoDBConnection')), __param(1, inject('Logger')), __param(2, inject('MongoOptions')), __param(2, optional()), __metadata("design:paramtypes", [mongoose.Connection, Object, Object])], CityRepository);export{CityRepository};//# sourceMappingURL=city-repository.js.map
