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 CityService = class CityService extends BaseService2 {
  cityRepository;
  logger;
  constructor(cityRepository, logger) {
    super(cityRepository);
    this.cityRepository = cityRepository;
    this.logger = logger.child({
      className: 'CityService'
    });
  }
  async getCitiesByState(state) {
    try {
      this.logger.trace('getCitiesByState with params (%j)', {
        state
      });
      if (!state) {
        throw new Error('State parameter is required');
      }
      const cities = await this.cityRepository.findByState(state);
      return cities;
    } catch (error) {
      this.logger.error('Error getting cities by state: %o', error?.message);
      throw error;
    }
  }
  async getCitiesByName(name) {
    try {
      this.logger.trace('getCitiesByName with params (%j)', {
        name
      });
      if (!name) {
        throw new Error('Name parameter is required');
      }
      const cities = await this.cityRepository.findByName(name);
      return cities;
    } catch (error) {
      this.logger.error('Error getting cities by name: %o', error?.message);
      throw error;
    }
  }
  async getCitiesByLocation(longitude, latitude, radiusInKm) {
    try {
      this.logger.trace('getCitiesByLocation 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 cities = await this.cityRepository.findByLocation(longitude, latitude, radiusInKm);
      return cities;
    } catch (error) {
      this.logger.error('Error getting cities by location: %o', error?.message);
      throw error;
    }
  }
  async createCity(cityData) {
    try {
      this.logger.trace('createCity with params (%j)', {
        ...cityData,
        location: '[Location]'
      });
      if (!cityData.name) {
        throw new Error('City name is required');
      }
      if (!cityData.state) {
        throw new Error('State is required for city creation');
      }
      if (!cityData.location || !cityData.location.coordinates) {
        throw new Error('Location coordinates are required');
      }
      const createdCity = await this.cityRepository.create(cityData);
      if (!createdCity) {
        throw new Error('Failed to create city');
      }
      return createdCity;
    } catch (error) {
      this.logger.error('Error creating city: %o', error?.message);
      throw error;
    }
  }
  async updateCity(cityId, updateData) {
    try {
      this.logger.trace('updateCity with params (%j)', {
        cityId,
        ...updateData,
        location: '[Location]'
      });
      if (!cityId) {
        throw new Error('City ID is required');
      }
      const updatedCity = await super.update(cityId, updateData, false);
      if (!updatedCity) {
        throw new Error('Failed to update city');
      }
      return updatedCity;
    } catch (error) {
      this.logger.error('Error updating city: %o', error?.message);
      throw error;
    }
  }
};
CityService = __decorate([injectable(), __param(0, inject(SERVER_TYPES.CityRepository)), __param(1, inject('Logger')), __metadata("design:paramtypes", [Object, Object])], CityService);export{CityService};//# sourceMappingURL=city-service.js.map
