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