import { SumsubService } from '#services/sumsub_service';
import { knowledgeAssessmentService } from '#services/knowledge_assessment_service';
import env from '#start/env';
export default class ComplianceController {
    async getSumSubToken({ auth, response }) {
        const user = auth.getUserOrFail();
        const profile = await user.related('individualProfile').query().firstOrFail();
        if (profile.complianceStep !== 'step_3') {
            return response.badRequest({
                errors: [{ message: `Action rejected. Current compliance step: ${profile.complianceStep}` }],
            });
        }
        try {
            const levelName = env.get('SUMSUB_LEVEL_NAME_INDIVIDUAL').trim();
            const token = await SumsubService.generateAccessToken(user.id, levelName);
            return response.ok({
                success: true,
                token,
            });
        }
        catch (error) {
            if (error.response) {
                return response.status(error.response.status).json({
                    success: false,
                    status: error.response.status,
                    sumsubError: error.response.data,
                    message: error.message,
                });
            }
            return response.internalServerError({
                success: false,
                errors: [{ message: error.message || 'Failed to generate identity verification session.' }],
            });
        }
    }
    async getKAQuestion({ auth, response }) {
        const user = auth.getUserOrFail();
        const profile = await user.related('individualProfile').query().firstOrFail();
        if (profile.complianceStep !== 'step_3') {
            return response.badRequest({
                errors: [{ message: `Action rejected. Current compliance step: ${profile.complianceStep}` }],
            });
        }
        try {
            const qa = await knowledgeAssessmentService.KnowledgeAssessment();
            return response.ok({
                success: true,
                qa,
            });
        }
        catch (error) {
            if (error.response) {
                return response.status(error.response.status).json({
                    success: false,
                    message: 'Error fetching knowledge assessment question library',
                });
            }
            return response.internalServerError({
                success: false,
                errors: ['Failed to generate knowdlege assessment library.'],
            });
        }
    }
    async showStepThree({ auth, view }) {
        const user = auth.user;
        let profile = null;
        if (user.accountType === 'individual') {
            profile = await user.related('individualProfile').query().first();
        }
        else if (user.accountType === 'business') {
            profile = await user.related('businessProfile').query().first();
        }
        if (!profile) {
        }
        if (profile.complianceStep === 'step_4' || profile.complianceStep === 'completed') {
        }
        return view.render('compliance/step_3', {
            user: {
                id: user.id,
                email: user.email,
                accountType: user.accountType,
            },
            profile: {
                complianceStep: profile.complianceStep,
                kycStatus: profile.kycStatus,
            },
        });
    }
}
//# sourceMappingURL=compliance_controller.js.map