"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.KycPublicCallbackController = exports.KycController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const JwtAuthGuard_1 = require("../user/auth/JwtAuthGuard");
const didit_dto_1 = require("./didit.dto");
const kyc_verification_service_1 = require("./kyc-verification.service");
let KycController = class KycController {
    constructor(kycVerificationService) {
        this.kycVerificationService = kycVerificationService;
    }
    async createKycSession(dto, req) {
        const userId = req?.user?.userId;
        return this.kycVerificationService.createSession(userId, dto);
    }
    async getStatus(req) {
        return this.kycVerificationService.getUserStatus(req?.user?.userId);
    }
    async getHistory(req) {
        return this.kycVerificationService.getUserHistory(req?.user?.userId);
    }
};
exports.KycController = KycController;
__decorate([
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, common_1.Post)('session'),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [didit_dto_1.CreateDiditSessionDto, Object]),
    __metadata("design:returntype", Promise)
], KycController.prototype, "createKycSession", null);
__decorate([
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, common_1.Get)('status'),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], KycController.prototype, "getStatus", null);
__decorate([
    (0, common_1.UseGuards)(JwtAuthGuard_1.JwtAuthGuard),
    (0, common_1.Get)('history'),
    __param(0, (0, common_1.Req)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], KycController.prototype, "getHistory", null);
exports.KycController = KycController = __decorate([
    (0, swagger_1.ApiTags)('kyc'),
    (0, swagger_1.ApiBearerAuth)(),
    (0, common_1.Controller)('app/kyc'),
    __metadata("design:paramtypes", [kyc_verification_service_1.KycVerificationService])
], KycController);
let KycPublicCallbackController = class KycPublicCallbackController {
    kycCallback(status, verificationSessionId, res) {
        const finalSessionId = verificationSessionId || '';
        const statusParam = encodeURIComponent(status || '');
        const verificationSessionIdParam = encodeURIComponent(finalSessionId);
        const deepLink = `cars24x7userapp://kyc/callback?status=${statusParam}&verificationSessionId=${verificationSessionIdParam}`;
        let statusClass = 'pending';
        if (status?.toLowerCase() === 'approved')
            statusClass = 'success';
        else if (status?.toLowerCase() === 'declined' || status?.toLowerCase() === 'failed')
            statusClass = 'failed';
        const html = `
      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>KYC Status</title>
        <style>
          body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; background-color: #f4f4f9; color: #333; }
          .container { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); text-align: center; max-width: 400px; width: 90%; }
          h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
          p { color: #666; margin-bottom: 1.5rem; }
          .status { display: inline-block; padding: 0.5rem 1rem; border-radius: 8px; font-weight: bold; margin-bottom: 1.5rem; text-transform: capitalize; }
          .status.success { background-color: #e8f5e9; color: #2e7d32; }
          .status.pending { background-color: #fff3e0; color: #ef6c00; }
          .status.failed { background-color: #ffebee; color: #c62828; }
          .btn { display: inline-block; padding: 0.75rem 1.5rem; background-color: #000; color: #fff; text-decoration: none; border-radius: 8px; font-weight: bold; width: 100%; box-sizing: border-box; }
          .btn:hover { background-color: #333; }
        </style>
      </head>
      <body>
        <div class="container">
          <h1>Pending Review</h1>
          <div class="status ${statusClass}">Status: ${status || 'Pending'}</div>
          <p>Your KYC process has finished. You can safely close this page and return to the application.</p>
        </div>
      </body>
      </html>
    `;
        res.setHeader('Content-Type', 'text/html');
        res.send(html);
    }
};
exports.KycPublicCallbackController = KycPublicCallbackController;
__decorate([
    (0, common_1.Get)('callback'),
    __param(0, (0, common_1.Query)('status')),
    __param(1, (0, common_1.Query)('verificationSessionId')),
    __param(2, (0, common_1.Res)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, Object]),
    __metadata("design:returntype", void 0)
], KycPublicCallbackController.prototype, "kycCallback", null);
exports.KycPublicCallbackController = KycPublicCallbackController = __decorate([
    (0, common_1.Controller)('kyc')
], KycPublicCallbackController);
//# sourceMappingURL=kyc.controller.js.map