"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.CaptiveController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const captive_service_1 = require("./captive.service");
const public_decorator_1 = require("../common/decorators/public.decorator");
const captive_dto_1 = require("./dto/captive.dto");
let CaptiveController = class CaptiveController {
    constructor(captiveService) {
        this.captiveService = captiveService;
    }
    async getPortalConfig(routerId) {
        return this.captiveService.getPortalConfig(routerId);
    }
    async getPackages(routerId) {
        return this.captiveService.getPackagesForPortal(routerId);
    }
    async getPackageDetail(packageId) {
        return this.captiveService.getPackageDetail(packageId);
    }
    async initiatePayment(dto, req) {
        const clientIp = req.ip || req.connection?.remoteAddress || 'unknown';
        return this.captiveService.initiatePayment(dto, clientIp);
    }
    async checkPaymentStatus(checkoutRequestId) {
        return this.captiveService.checkPaymentStatus(checkoutRequestId);
    }
    async getPaymentResult(reference) {
        return this.captiveService.getPaymentResult(reference);
    }
    async redeemVoucher(dto) {
        return this.captiveService.redeemVoucher(dto);
    }
    async checkSession(macAddress, ipAddress) {
        return this.captiveService.getCustomerSession(macAddress || '', ipAddress || '');
    }
    async loginCustomer(dto) {
        return this.captiveService.loginCustomer(dto.phoneNumber);
    }
    async verifyOtp(dto) {
        return this.captiveService.verifyOtp(dto.phoneNumber, dto.otp, dto.sessionId);
    }
    async detectDevice(macAddress, ipAddress) {
        return this.captiveService.detectDevice(macAddress, ipAddress);
    }
};
exports.CaptiveController = CaptiveController;
__decorate([
    (0, common_1.Get)('config/:routerId'),
    (0, swagger_1.ApiOperation)({ summary: 'Get portal configuration for a router' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Portal configuration' }),
    __param(0, (0, common_1.Param)('routerId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "getPortalConfig", null);
__decorate([
    (0, common_1.Get)('packages/:routerId'),
    (0, swagger_1.ApiOperation)({ summary: 'Get available packages for the captive portal' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'List of available packages' }),
    __param(0, (0, common_1.Param)('routerId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "getPackages", null);
__decorate([
    (0, common_1.Get)('packages/detail/:packageId'),
    (0, swagger_1.ApiOperation)({ summary: 'Get detailed package info' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Package detail' }),
    __param(0, (0, common_1.Param)('packageId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "getPackageDetail", null);
__decorate([
    (0, common_1.Post)('payments/initiate'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Initiate M-Pesa payment from captive portal (rate limited: 3/min/IP)' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Payment initiated' }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [captive_dto_1.CaptivePaymentDto, Object]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "initiatePayment", null);
__decorate([
    (0, common_1.Get)('payments/status/:checkoutRequestId'),
    (0, swagger_1.ApiOperation)({ summary: 'Check payment status' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Payment status' }),
    __param(0, (0, common_1.Param)('checkoutRequestId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "checkPaymentStatus", null);
__decorate([
    (0, common_1.Get)('payments/result/:reference'),
    (0, swagger_1.ApiOperation)({ summary: 'Get payment result for success page display' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Payment result' }),
    __param(0, (0, common_1.Param)('reference')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "getPaymentResult", null);
__decorate([
    (0, common_1.Post)('vouchers/redeem'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Redeem voucher from captive portal' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Voucher redeemed successfully' }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [captive_dto_1.RedeemVoucherPortalDto]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "redeemVoucher", null);
__decorate([
    (0, common_1.Get)('session/check'),
    (0, swagger_1.ApiOperation)({ summary: 'Check if device has an active session' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Session check result' }),
    __param(0, (0, common_1.Query)('macAddress')),
    __param(1, (0, common_1.Query)('ipAddress')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "checkSession", null);
__decorate([
    (0, common_1.Post)('customers/login'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Request OTP for customer login' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'OTP sent' }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [captive_dto_1.CustomerLoginDto]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "loginCustomer", null);
__decorate([
    (0, common_1.Post)('customers/verify-otp'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Verify OTP and get auth token' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'OTP verified' }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [captive_dto_1.VerifyOtpDto]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "verifyOtp", null);
__decorate([
    (0, common_1.Get)('device/detect'),
    (0, swagger_1.ApiOperation)({ summary: 'Detect device and identify router from client info' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Device detection result' }),
    __param(0, (0, common_1.Query)('macAddress')),
    __param(1, (0, common_1.Query)('ipAddress')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String]),
    __metadata("design:returntype", Promise)
], CaptiveController.prototype, "detectDevice", null);
exports.CaptiveController = CaptiveController = __decorate([
    (0, swagger_1.ApiTags)('Captive Portal'),
    (0, common_1.Controller)('captive'),
    (0, public_decorator_1.Public)(),
    __metadata("design:paramtypes", [captive_service_1.CaptiveService])
], CaptiveController);
