"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.OnboardingController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const public_decorator_1 = require("../auth/public.decorator");
const swagger_docs_1 = require("../common/swagger-docs");
const onboarding_dto_1 = require("./dto/onboarding.dto");
const onboarding_service_1 = require("./onboarding.service");
let OnboardingController = class OnboardingController {
    onboardingService;
    constructor(onboardingService) {
        this.onboardingService = onboardingService;
    }
    listSubscriptionPlans() {
        return this.onboardingService.listSubscriptionPlans();
    }
    listPaymentProviders(estateId) {
        return this.onboardingService.listPaymentProviders(estateId);
    }
    submitEstateAdminLead(dto) {
        return this.onboardingService.submitEstateAdminLead(dto);
    }
    selectSubscriptionPlan(estateId, dto) {
        return this.onboardingService.selectSubscriptionPlan(estateId, dto);
    }
    initializePayment(estateId, dto) {
        return this.onboardingService.initializePayment(estateId, dto);
    }
    recordPayment(estateId, dto) {
        return this.onboardingService.recordPayment(estateId, dto);
    }
    handlePaymentCallback(query) {
        return this.onboardingService.handlePaymentCallback(query);
    }
};
exports.OnboardingController = OnboardingController;
__decorate([
    (0, common_1.Get)('subscription-plans'),
    (0, swagger_1.ApiOperation)({
        summary: 'List public subscription plans',
        description: 'Returns active estate subscription plans. Unit counts refer to residents/units/houses: Starter 0-100, Secure 101-500, Luxury 501-2000, Business 2001-5000. Enterprise remains a future/non-public custom plan.'
    }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Subscription plans returned.',
        schema: {
            example: [
                {
                    code: 'STARTER',
                    name: 'GateWise Starter',
                    minResidents: 0,
                    maxResidents: 100,
                    monthlyPriceKobo: 20000000,
                    currency: 'NGN',
                    customPricing: false
                },
                {
                    code: 'SECURE',
                    name: 'GateWise Secure',
                    minResidents: 101,
                    maxResidents: 500,
                    monthlyPriceKobo: 50000000,
                    currency: 'NGN',
                    customPricing: false
                },
                {
                    code: 'LUXURY',
                    name: 'GateWise Luxury',
                    minResidents: 501,
                    maxResidents: 2000,
                    monthlyPriceKobo: 200000000,
                    currency: 'NGN',
                    customPricing: false
                },
                {
                    code: 'BUSINESS',
                    name: 'GateWise Business',
                    minResidents: 2001,
                    maxResidents: 5000,
                    monthlyPriceKobo: 500000000,
                    currency: 'NGN',
                    customPricing: false
                }
            ]
        }
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "listSubscriptionPlans", null);
__decorate([
    (0, common_1.Get)('payment-providers'),
    (0, swagger_1.ApiOperation)({
        summary: 'List enabled payment providers',
        description: 'Returns global payment provider settings and, when estateId is supplied, the effective estate-specific setting after overrides.'
    }),
    (0, swagger_1.ApiQuery)({ name: 'estateId', required: false, example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Payment provider settings returned.',
        schema: {
            example: [
                {
                    provider: 'FLUTTERWAVE',
                    displayName: 'Flutterwave',
                    globallyEnabled: true,
                    estateEnabled: null,
                    effectiveEnabled: true,
                    recommendedUseCases: ['Nigeria payments', 'International/diaspora payments', 'Luxury estates']
                }
            ]
        }
    }),
    __param(0, (0, common_1.Query)('estateId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "listPaymentProviders", null);
__decorate([
    (0, common_1.Post)('estate-admin-signup'),
    (0, swagger_1.ApiOperation)({
        summary: 'Submit estate admin signup lead',
        description: 'Allows a prospective estate admin to register interest. This creates a PENDING estate and a suspended ESTATE_ADMIN account pending GateWise review, payment, and activation.'
    }),
    (0, swagger_1.ApiBody)({ type: onboarding_dto_1.EstateAdminLeadSignupDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Estate admin signup submitted.',
        schema: {
            example: {
                estate: {
                    id: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    name: 'GreenPark Estate',
                    location: 'Lagos, Nigeria',
                    unitCount: 120,
                    estateType: 'Residential gated community',
                    status: 'PENDING',
                    signupStatus: 'PENDING_APPROVAL'
                },
                admin: {
                    id: 'user-uuid',
                    name: 'Ade Okafor',
                    phone: '+2348000000990',
                    email: 'estate.admin@example.com',
                    role: 'ESTATE_ADMIN',
                    status: 'SUSPENDED'
                },
                nextStep: 'GateWise review is required before plan selection and activation.'
            }
        }
    }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [onboarding_dto_1.EstateAdminLeadSignupDto]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "submitEstateAdminLead", null);
__decorate([
    (0, common_1.Post)('estates/:estateId/select-plan'),
    (0, swagger_1.ApiOperation)({
        summary: 'Select subscription plan and payment provider',
        description: 'Used after GateWise approval. The estate admin identifies themselves by signup phone, then selects a plan and enabled payment provider.'
    }),
    (0, swagger_1.ApiParam)({ name: 'estateId', example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiBody)({ type: onboarding_dto_1.SelectSubscriptionPlanDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Plan selected.',
        schema: {
            example: {
                estate: {
                    id: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    subscriptionStatus: 'PLAN_SELECTED',
                    selectedPaymentProvider: 'FLUTTERWAVE',
                    subscriptionPlan: { code: 'SECURE', name: 'GateWise Secure' }
                },
                nextStep: 'Initialize a hosted payment checkout, then return for payment confirmation.'
            }
        }
    }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Param)('estateId')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, onboarding_dto_1.SelectSubscriptionPlanDto]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "selectSubscriptionPlan", null);
__decorate([
    (0, common_1.Post)('estates/:estateId/payments/initialize'),
    (0, swagger_1.ApiOperation)({
        summary: 'Initialize hosted payment',
        description: 'Creates a pending estate subscription payment and initializes a hosted checkout session with the selected payment provider. Open the returned checkoutUrl to complete payment.'
    }),
    (0, swagger_1.ApiParam)({ name: 'estateId', example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiBody)({ type: onboarding_dto_1.InitializeEstatePaymentDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Sandbox checkout initialized.',
        schema: {
            example: {
                payment: {
                    id: 'payment-uuid',
                    estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    provider: 'FLUTTERWAVE',
                    reference: 'FLU-1778881112222-a1b2c3d4',
                    status: 'PENDING'
                },
                checkout: {
                    provider: 'FLUTTERWAVE',
                    mode: 'sandbox',
                    reference: 'FLU-1778881112222-a1b2c3d4',
                    providerReference: 'FLU-1778881112222-a1b2c3d4',
                    checkoutUrl: 'https://checkout.flutterwave.com/v3/hosted/pay/example',
                    accessCode: null
                },
                nextStep: 'Open checkoutUrl, complete payment, then wait for GateWise confirmation.'
            }
        }
    }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Param)('estateId')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, onboarding_dto_1.InitializeEstatePaymentDto]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "initializePayment", null);
__decorate([
    (0, common_1.Post)('estates/:estateId/payments'),
    (0, swagger_1.ApiOperation)({
        summary: 'Record manual payment reference',
        description: 'Records a pending manual/offline payment reference after transfer or non-hosted checkout. Hosted sandbox checkout should use /payments/initialize.'
    }),
    (0, swagger_1.ApiParam)({ name: 'estateId', example: swagger_docs_1.ESTATE_ID_EXAMPLE }),
    (0, swagger_1.ApiBody)({ type: onboarding_dto_1.RecordEstatePaymentDto }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'Payment reference recorded.',
        schema: {
            example: {
                payment: {
                    id: 'payment-uuid',
                    estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    provider: 'FLUTTERWAVE',
                    reference: 'FLW-TEST-REFERENCE-001',
                    status: 'PENDING'
                },
                nextStep: 'GateWise must confirm the payment before the estate becomes active.'
            }
        }
    }),
    (0, swagger_docs_1.ApiValidationError)(),
    __param(0, (0, common_1.Param)('estateId')),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, onboarding_dto_1.RecordEstatePaymentDto]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "recordPayment", null);
__decorate([
    (0, common_1.Get)('payments/callback'),
    (0, swagger_1.ApiOperation)({
        summary: 'Receive hosted payment redirect callback',
        description: 'Stores the gateway redirect query parameters after hosted checkout. This does not activate the estate by itself; GateWise payment confirmation still verifies the gateway and activates the estate.'
    }),
    (0, swagger_1.ApiQuery)({ name: 'provider', required: false, example: 'FLUTTERWAVE' }),
    (0, swagger_1.ApiQuery)({ name: 'reference', required: false, example: 'FLU-1778881112222-a1b2c3d4' }),
    (0, swagger_1.ApiQuery)({ name: 'tx_ref', required: false, example: 'FLU-1778881112222-a1b2c3d4' }),
    (0, swagger_1.ApiQuery)({ name: 'transaction_id', required: false, example: '123456789' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Payment callback stored.',
        schema: {
            example: {
                status: 'received',
                payment: {
                    id: 'payment-uuid',
                    estateId: swagger_docs_1.ESTATE_ID_EXAMPLE,
                    provider: 'FLUTTERWAVE',
                    reference: 'FLU-1778881112222-a1b2c3d4',
                    status: 'PENDING'
                },
                nextStep: 'Payment callback stored. GateWise should confirm the payment to activate the estate.'
            }
        }
    }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], OnboardingController.prototype, "handlePaymentCallback", null);
exports.OnboardingController = OnboardingController = __decorate([
    (0, public_decorator_1.Public)(),
    (0, swagger_1.ApiTags)('Onboarding'),
    (0, common_1.Controller)({ path: 'onboarding', version: '1' }),
    __metadata("design:paramtypes", [onboarding_service_1.OnboardingService])
], OnboardingController);
//# sourceMappingURL=onboarding.controller.js.map