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 StateService = class StateService extends BaseService2 {
  stateRepository;
  logger;
  constructor(stateRepository, logger) {
    super(stateRepository);
    this.stateRepository = stateRepository;
    this.logger = logger.child({
      className: 'StateService'
    });
  }
  async getStatesByCountry(country) {
    try {
      this.logger.trace('getStatesByCountry with params (%j)', {
        country
      });
      if (!country) {
        throw new Error('Country parameter is required');
      }
      const states = await this.stateRepository.findByCountry(country);
      return states;
    } catch (error) {
      this.logger.error('Error getting states by country: %o', error?.message);
      throw error;
    }
  }
  async getStateByName(name) {
    try {
      this.logger.trace('getStateByName with params (%j)', {
        name
      });
      if (!name) {
        throw new Error('Name parameter is required');
      }
      const state = await this.stateRepository.findByName(name);
      return state;
    } catch (error) {
      this.logger.error('Error getting state by name: %o', error?.message);
      throw error;
    }
  }
  async getStatesByLocation(longitude, latitude, radiusInKm) {
    try {
      this.logger.trace('getStatesByLocation 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 states = await this.stateRepository.findByLocation(longitude, latitude, radiusInKm);
      return states;
    } catch (error) {
      this.logger.error('Error getting states by location: %o', error?.message);
      throw error;
    }
  }
  async createState(stateData) {
    try {
      this.logger.trace('createState with params (%j)', {
        ...stateData,
        location: '[Location]'
      });
      if (!stateData.name) {
        throw new Error('State name is required');
      }
      if (!stateData.country) {
        throw new Error('Country is required for state creation');
      }
      if (!stateData.location || !stateData.location.coordinates) {
        throw new Error('Location coordinates are required');
      }
      const createdState = await this.stateRepository.create(stateData);
      if (!createdState) {
        throw new Error('Failed to create state');
      }
      return createdState;
    } catch (error) {
      this.logger.error('Error creating state: %o', error?.message);
      throw error;
    }
  }
  async updateState(stateId, updateData) {
    try {
      this.logger.trace('updateState with params (%j)', {
        stateId,
        ...updateData,
        location: '[Location]'
      });
      if (!stateId) {
        throw new Error('State ID is required');
      }
      const updatedState = await super.update(stateId, updateData, false);
      if (!updatedState) {
        throw new Error('Failed to update state');
      }
      return updatedState;
    } catch (error) {
      this.logger.error('Error updating state: %o', error?.message);
      throw error;
    }
  }
};
StateService = __decorate([injectable(), __param(0, inject(SERVER_TYPES.StateRepository)), __param(1, inject('Logger')), __metadata("design:paramtypes", [Object, Object])], StateService);export{StateService};//# sourceMappingURL=state-service.js.map
