"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.LocationsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const locations_service_1 = require("./locations.service");
const jwt_auth_guard_1 = require("../common/guard/jwt-auth.guard");
const current_business_decorator_1 = require("../common/decorators/current-business.decorator");
const location_dto_1 = require("./dto/location.dto");
let LocationsController = class LocationsController {
    constructor(locationsService) {
        this.locationsService = locationsService;
    }
    async listLocations(business) {
        return this.locationsService.findAll(business.id);
    }
    async createLocation(dto, business) {
        return this.locationsService.create(dto, business.id);
    }
    async getLocation(id, business) {
        return this.locationsService.findOne(id, business.id);
    }
    async updateLocation(id, dto, business) {
        return this.locationsService.update(id, dto, business.id);
    }
    async deleteLocation(id, business) {
        await this.locationsService.delete(id, business.id);
    }
    async getLocationStats(id, business) {
        return this.locationsService.getLocationStats(id, business.id);
    }
    async getLocationRouters(id, business) {
        return this.locationsService.getLocationRouters(id, business.id);
    }
    async assignRouter(id, routerId, business) {
        return this.locationsService.assignRouter(id, routerId, business.id);
    }
    async removeRouter(id, routerId, business) {
        return this.locationsService.removeRouter(id, routerId);
    }
};
exports.LocationsController = LocationsController;
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: 'List all locations for the current business' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Returns list of locations' }),
    __param(0, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "listLocations", null);
__decorate([
    (0, common_1.Post)(),
    (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
    (0, swagger_1.ApiOperation)({ summary: 'Create a new location' }),
    (0, swagger_1.ApiResponse)({ status: 201, description: 'Location created' }),
    (0, swagger_1.ApiResponse)({ status: 400, description: 'Validation error or limit reached' }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [location_dto_1.CreateLocationDto, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "createLocation", null);
__decorate([
    (0, common_1.Get)(':id'),
    (0, swagger_1.ApiOperation)({ summary: 'Get location details with routers and packages' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Location details' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "getLocation", null);
__decorate([
    (0, common_1.Put)(':id'),
    (0, swagger_1.ApiOperation)({ summary: 'Update a location' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Location updated' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, location_dto_1.UpdateLocationDto, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "updateLocation", null);
__decorate([
    (0, common_1.Delete)(':id'),
    (0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
    (0, swagger_1.ApiOperation)({ summary: 'Delete a location (only if no active routers)' }),
    (0, swagger_1.ApiResponse)({ status: 204, description: 'Location deleted' }),
    (0, swagger_1.ApiResponse)({ status: 400, description: 'Cannot delete - active routers present' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "deleteLocation", null);
__decorate([
    (0, common_1.Get)(':id/stats'),
    (0, swagger_1.ApiOperation)({ summary: 'Get location statistics (sessions, revenue)' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Location stats' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "getLocationStats", null);
__decorate([
    (0, common_1.Get)(':id/routers'),
    (0, swagger_1.ApiOperation)({ summary: 'Get routers at this location' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'List of routers at location' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "getLocationRouters", null);
__decorate([
    (0, common_1.Post)(':id/routers/:routerId'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Assign a router to this location' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Router assigned' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Location or router not found' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Param)('routerId')),
    __param(2, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "assignRouter", null);
__decorate([
    (0, common_1.Delete)(':id/routers/:routerId'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Remove router from this location' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Router removed from location' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'Router not found at location' }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Param)('routerId')),
    __param(2, (0, current_business_decorator_1.CurrentBusiness)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", Promise)
], LocationsController.prototype, "removeRouter", null);
exports.LocationsController = LocationsController = __decorate([
    (0, swagger_1.ApiTags)('Locations'),
    (0, common_1.Controller)('locations'),
    (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
    (0, swagger_1.ApiBearerAuth)(),
    __metadata("design:paramtypes", [locations_service_1.LocationsService])
], LocationsController);
