"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeocodingController = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const geocoding_service_1 = require("./geocoding.service"); const admin_boundaries_service_1 = require("./admin-boundaries.service"); const jordan_research_service_1 = require("./jordan-research.service"); const administrative_linking_service_1 = require("./administrative-linking.service"); const map_refinement_service_1 = require("./map-refinement.service"); const api_key_guard_1 = require("../common/guards/api-key.guard"); const admin_guard_1 = require("../common/guards/admin.guard"); const rate_limiter_guard_1 = require("../common/guards/rate-limiter.guard"); const search_query_dto_1 = require("./dto/search-query.dto"); const reverse_geocode_dto_1 = require("./dto/reverse-geocode.dto"); let GeocodingController = class GeocodingController { geocodingService; adminBoundariesService; jordanResearchService; adminLinkingService; refinementService; constructor(geocodingService, adminBoundariesService, jordanResearchService, adminLinkingService, refinementService) { this.geocodingService = geocodingService; this.adminBoundariesService = adminBoundariesService; this.jordanResearchService = jordanResearchService; this.adminLinkingService = adminLinkingService; this.refinementService = refinementService; } async search(queryDto) { const { q, lat, lng, radius, country } = queryDto; return this.geocodingService.searchPlaces(q, lat, lng, radius, country); } async autocomplete(q, country) { if (!q || q.trim().length < 2) return { results: [] }; return this.geocodingService.autocomplete(q, country); } async reverse(reverseDto) { const { lat, lng } = reverseDto; return this.geocodingService.reverseGeocode(lat, lng); } async addPlace(req, placeData) { const userId = req.user?.uid || req.tenant?.id || 'api_key_user'; return this.refinementService.suggestPlace(placeData, userId); } async deletePlace(country, name, id) { if (id) { return this.geocodingService.deletePlaceById(Number(id), country); } if (name) { return this.geocodingService.deletePlacesByName(name, country); } throw new common_1.HttpException('Name or ID required', common_1.HttpStatus.BAD_REQUEST); } async upsertPlace(placeData) { return this.geocodingService.upsertPlace(placeData); } async upsertBatch(body) { return this.geocodingService.upsertBatch(body.places); } async getPlaces(limit) { return this.geocodingService.getRecentPlaces(limit ? parseInt(limit, 10) : 50); } async getGeoJSON() { return this.geocodingService.getAllPlacesGeoJSON(); } async importBoundaries(country, filePath) { return this.adminBoundariesService.importFromFile(country, filePath); } async zarqaResearch() { return this.jordanResearchService.generateZarqaReport(); } async syncNeighborhoods(bbox, country) { return this.adminLinkingService.syncOsmNeighborhoodPoints(bbox, country); } async generateVoronoi(country) { return this.adminLinkingService.generateVoronoiNeighborhoods(country); } async linkPlaces(country) { return this.adminLinkingService.linkPlaces(country); } }; exports.GeocodingController = GeocodingController; __decorate([ (0, common_1.Get)('search'), (0, swagger_1.ApiOperation)({ summary: 'Search for locations (Forward Geocoding)' }), __param(0, (0, common_1.Query)()), __metadata("design:type", Function), __metadata("design:paramtypes", [search_query_dto_1.SearchQueryDto]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "search", null); __decorate([ (0, common_1.Get)('autocomplete'), (0, swagger_1.ApiOperation)({ summary: 'Fast autocomplete for live typing' }), (0, swagger_1.ApiQuery)({ name: 'q', required: true }), (0, swagger_1.ApiQuery)({ name: 'country', required: false }), __param(0, (0, common_1.Query)('q')), __param(1, (0, common_1.Query)('country')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "autocomplete", null); __decorate([ (0, common_1.Get)('reverse'), (0, swagger_1.ApiOperation)({ summary: 'Reverse Geocoding (Lat/Lng to Address)' }), __param(0, (0, common_1.Query)()), __metadata("design:type", Function), __metadata("design:paramtypes", [reverse_geocode_dto_1.ReverseGeocodeDto]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "reverse", null); __decorate([ (0, common_1.Post)('places'), (0, swagger_1.ApiOperation)({ summary: 'Add a new location (User Submitted - Goes to Audit)' }), __param(0, (0, common_1.Req)()), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "addPlace", null); __decorate([ (0, common_1.Delete)('places'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Delete a place by name or ID' }), (0, swagger_1.ApiQuery)({ name: 'name', required: false }), (0, swagger_1.ApiQuery)({ name: 'id', required: false, type: Number }), (0, swagger_1.ApiQuery)({ name: 'country', required: true, enum: ['jordan', 'syria', 'egypt'] }), __param(0, (0, common_1.Query)('country')), __param(1, (0, common_1.Query)('name')), __param(2, (0, common_1.Query)('id')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "deletePlace", null); __decorate([ (0, common_1.Post)('upsert-place'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Add or Update a location (Automated Scraper)' }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "upsertPlace", null); __decorate([ (0, common_1.Post)('upsert-batch'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Add or Update multiple locations in bulk' }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "upsertBatch", null); __decorate([ (0, common_1.Get)('places'), (0, swagger_1.ApiOperation)({ summary: 'Get recent user submitted places' }), __param(0, (0, common_1.Query)('limit')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "getPlaces", null); __decorate([ (0, common_1.Get)('geojson'), (0, swagger_1.ApiOperation)({ summary: 'Get all user submitted places as GeoJSON for Map Style' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "getGeoJSON", null); __decorate([ (0, common_1.Post)('import-boundaries'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Import administrative boundaries from a local GeoJSON file on the server' }), (0, swagger_1.ApiQuery)({ name: 'country', required: true }), (0, swagger_1.ApiQuery)({ name: 'filePath', required: true }), __param(0, (0, common_1.Query)('country')), __param(1, (0, common_1.Query)('filePath')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "importBoundaries", null); __decorate([ (0, common_1.Get)('research/zarqa'), (0, swagger_1.ApiOperation)({ summary: 'Generate a research report for Zarqa, Jordan (Sample Data)' }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "zarqaResearch", null); __decorate([ (0, common_1.Post)('admin/sync-neighborhoods'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Sync neighborhood points from OSM for a bbox' }), (0, swagger_1.ApiQuery)({ name: 'bbox', required: false }), (0, swagger_1.ApiQuery)({ name: 'country', required: false, enum: ['jordan', 'syria', 'egypt'] }), __param(0, (0, common_1.Query)('bbox')), __param(1, (0, common_1.Query)('country')), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "syncNeighborhoods", null); __decorate([ (0, common_1.Post)('admin/generate-voronoi'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Generate Voronoi polygons for neighborhoods' }), (0, swagger_1.ApiQuery)({ name: 'country', required: false, enum: ['jordan', 'syria', 'egypt'] }), __param(0, (0, common_1.Query)('country')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "generateVoronoi", null); __decorate([ (0, common_1.Post)('admin/link-places'), (0, common_1.UseGuards)(admin_guard_1.AdminGuard), (0, swagger_1.ApiOperation)({ summary: 'Link places to administrative hierarchy' }), (0, swagger_1.ApiQuery)({ name: 'country', required: true, enum: ['jordan', 'syria', 'egypt'] }), __param(0, (0, common_1.Query)('country')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], GeocodingController.prototype, "linkPlaces", null); exports.GeocodingController = GeocodingController = __decorate([ (0, swagger_1.ApiTags)('geocoding'), (0, swagger_1.ApiHeader)({ name: 'x-api-key', description: 'Multi-tenant API Key', required: true }), (0, common_1.Controller)('geocoding'), (0, common_1.UseGuards)(api_key_guard_1.ApiKeyGuard, rate_limiter_guard_1.TenantThrottlerGuard), __metadata("design:paramtypes", [geocoding_service_1.GeocodingService, admin_boundaries_service_1.AdminBoundariesService, jordan_research_service_1.JordanResearchService, administrative_linking_service_1.AdministrativeLinkingService, map_refinement_service_1.MapRefinementService]) ], GeocodingController); //# sourceMappingURL=geocoding.controller.js.map