import {__decorate,__param,__metadata}from'tslib';import {injectable,inject}from'inversify';import'@cdm-logger/core';import {BaseService2}from'@common-stack/store-mongo';import {SERVER_TYPES}from'common/server';let CountryService = class CountryService extends BaseService2 {
  countryRepository;
  logger;
  constructor(countryRepository, logger) {
    super(countryRepository);
    this.countryRepository = countryRepository;
    this.logger = logger.child({
      className: 'CountryService'
    });
  }
  async getCountryByName(name) {
    try {
      this.logger.trace('getCountryByName with params (%j)', {
        name
      });
      if (!name) {
        throw new Error('Name parameter is required');
      }
      const country = await this.countryRepository.findByName(name);
      return country;
    } catch (error) {
      this.logger.error('Error getting country by name: %o', error?.message);
      throw error;
    }
  }
  async getCountriesByPhoneCode(phoneCode) {
    try {
      this.logger.trace('getCountriesByPhoneCode with params (%j)', {
        phoneCode
      });
      if (!phoneCode) {
        throw new Error('Phone code parameter is required');
      }
      const countries = await this.countryRepository.findByPhoneCode(phoneCode);
      return countries;
    } catch (error) {
      this.logger.error('Error getting countries by phone code: %o', error?.message);
      throw error;
    }
  }
  async getCountriesByCurrency(currency) {
    try {
      this.logger.trace('getCountriesByCurrency with params (%j)', {
        currency
      });
      if (!currency) {
        throw new Error('Currency parameter is required');
      }
      const countries = await this.countryRepository.findByCurrency(currency);
      return countries;
    } catch (error) {
      this.logger.error('Error getting countries by currency: %o', error?.message);
      throw error;
    }
  }
  async getCountriesByLocation(longitude, latitude, radiusInKm) {
    try {
      this.logger.trace('getCountriesByLocation with params (%j)', {
        longitude,
        latitude,
        radiusInKm
      });
      if (typeof longitude !== 'number' || typeof latitude !== 'number' || typeof radiusInKm !== 'number') {
        throw new Error('Longitude, latitude, and radiusInKm must be numbers');
      }
      if (radiusInKm <= 0) {
        throw new Error('Radius must be greater than 0');
      }
      const countries = await this.countryRepository.findByLocation(longitude, latitude, radiusInKm);
      return countries;
    } catch (error) {
      this.logger.error('Error getting countries by location: %o', error?.message);
      throw error;
    }
  }
  async createCountry(countryData) {
    try {
      this.logger.trace('createCountry with params (%j)', {
        ...countryData,
        location: '[Location]'
      });
      if (!countryData.name) {
        throw new Error('Country name is required');
      }
      if (!countryData.location || !countryData.location.coordinates) {
        throw new Error('Location coordinates are required');
      }
      const createdCountry = await this.countryRepository.create(countryData);
      if (!createdCountry) {
        throw new Error('Failed to create country');
      }
      return createdCountry;
    } catch (error) {
      this.logger.error('Error creating country: %o', error?.message);
      throw error;
    }
  }
  async updateCountry(countryId, updateData) {
    try {
      this.logger.trace('updateCountry with params (%j)', {
        countryId,
        ...updateData,
        location: '[Location]'
      });
      if (!countryId) {
        throw new Error('Country ID is required');
      }
      const updatedCountry = await super.update(countryId, updateData, false);
      if (!updatedCountry) {
        throw new Error('Failed to update country');
      }
      return updatedCountry;
    } catch (error) {
      this.logger.error('Error updating country: %o', error?.message);
      throw error;
    }
  }
};
CountryService = __decorate([injectable(), __param(0, inject(SERVER_TYPES.CountryRepository)), __param(1, inject('Logger')), __metadata("design:paramtypes", [Object, Object])], CountryService);export{CountryService};//# sourceMappingURL=country-service.js.map
