"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OffboardingService = void 0;
const common_1 = require("@nestjs/common");
const config_1 = require("../../config");
const entities_1 = require("../../config/database/entities");
const utils_1 = require("../../utils");
const notifications_service_1 = require("../notifications/notifications.service");
let OffboardingService = class OffboardingService {
    constructor(db, notificationsService) {
        this.db = db;
        this.notificationsService = notificationsService;
    }
    async createTemplate(data, ownerId) {
        try {
            const template = await this.db.offboarding_templates.create({
                data: {
                    title: data.title,
                    description: data.description,
                    is_active: data.is_active ?? true,
                    owner_id: ownerId,
                },
            });
            if (data.tasks && data.tasks.length > 0) {
                for (let i = 0; i < data.tasks.length; i++) {
                    const t = data.tasks[i];
                    await this.db.offboarding_template_tasks.create({
                        data: {
                            template_id: template.id,
                            title: t.title,
                            description: t.description,
                            owner_type: t.owner_type,
                            priority: t.priority,
                            relative_due_days: t.relative_due_days,
                            order_index: t.order_index ?? i,
                        },
                    });
                }
            }
            return this.getTemplateById(template.id, ownerId);
        }
        catch (error) {
            config_1.logger.error('Failed to create offboarding template', error);
            throw error;
        }
    }
    async seedDefaultTemplates(ownerId) {
        try {
            if (!ownerId)
                return;
            const existingCount = await this.db.offboarding_templates.count({
                where: { owner_id: ownerId },
            });
            if (existingCount > 0)
                return;
            const templatesToSeed = [
                {
                    title: 'Standard Offboarding',
                    description: 'Standard company offboarding checklist for departing employees.',
                    is_active: true,
                    tasks: [
                        {
                            title: 'Revoke IT Systems & Email Credentials Access',
                            description: 'Deactivate SSO, Google Workspace, Slack, and internal tools',
                            owner_type: entities_1.TaskOwnerTypeEnum.it,
                            priority: 'critical',
                            relative_due_days: 0,
                        },
                        {
                            title: 'Collect Laptop, Monitor & Company Property',
                            description: 'Return hardware equipment and security badges',
                            owner_type: entities_1.TaskOwnerTypeEnum.it,
                            priority: 'high',
                            relative_due_days: 1,
                        },
                        {
                            title: 'Complete Exit Interview Survey & Feedback Session',
                            description: 'Schedule exit interview and record feedback',
                            owner_type: entities_1.TaskOwnerTypeEnum.hr,
                            priority: 'medium',
                            relative_due_days: 3,
                        },
                        {
                            title: 'Knowledge Transfer & Handover Documentation',
                            description: 'Handover ongoing projects and document key operational processes',
                            owner_type: entities_1.TaskOwnerTypeEnum.employee,
                            priority: 'high',
                            relative_due_days: 5,
                        },
                        {
                            title: 'Final Settlement & Payroll Calculation',
                            description: 'Calculate pending salary, leave encashment, and release final pay',
                            owner_type: entities_1.TaskOwnerTypeEnum.finance,
                            priority: 'high',
                            relative_due_days: 7,
                        },
                    ],
                },
                {
                    title: 'Executive Offboarding',
                    description: 'Offboarding workflow for Senior Executives, Directors, and Department Heads.',
                    is_active: true,
                    tasks: [
                        {
                            title: 'Board & Leadership Team Notification',
                            description: 'Notify executive team and organize transition plan',
                            owner_type: entities_1.TaskOwnerTypeEnum.hr,
                            priority: 'high',
                            relative_due_days: 1,
                        },
                        {
                            title: 'Legal NDA & Non-Compete Agreement Review',
                            description: 'Review confidentiality obligations and post-employment covenants',
                            owner_type: entities_1.TaskOwnerTypeEnum.hr,
                            priority: 'high',
                            relative_due_days: 2,
                        },
                        {
                            title: 'Executive Corporate Card & Banking Access Revocation',
                            description: 'Cancel corporate credit cards and revoke banking signatory rights',
                            owner_type: entities_1.TaskOwnerTypeEnum.finance,
                            priority: 'critical',
                            relative_due_days: 1,
                        },
                        {
                            title: 'Strategic Handover Briefing to Successor',
                            description: 'Conduct strategic handoff sessions and transfer key stakeholder relationships',
                            owner_type: entities_1.TaskOwnerTypeEnum.manager,
                            priority: 'high',
                            relative_due_days: 5,
                        },
                    ],
                },
            ];
            for (const tplData of templatesToSeed) {
                const { tasks, ...templateFields } = tplData;
                const template = await this.db.offboarding_templates.create({
                    data: {
                        ...templateFields,
                        owner_id: ownerId,
                    },
                });
                if (tasks && tasks.length > 0) {
                    for (let i = 0; i < tasks.length; i++) {
                        const t = tasks[i];
                        await this.db.offboarding_template_tasks.create({
                            data: {
                                template_id: template.id,
                                title: t.title,
                                description: t.description,
                                owner_type: t.owner_type,
                                priority: t.priority,
                                relative_due_days: t.relative_due_days,
                                order_index: i,
                            },
                        });
                    }
                }
            }
        }
        catch (error) {
            config_1.logger.error('Failed to seed default offboarding templates', error);
        }
    }
    async getTemplates(ownerId) {
        await this.seedDefaultTemplates(ownerId);
        return await this.db.offboarding_templates.findMany({
            where: { owner_id: ownerId },
            include: { tasks: true },
            orderBy: { created_at: 'desc' },
        });
    }
    async getTemplateById(id, ownerId) {
        const template = await this.db.offboarding_templates.findFirst({
            where: { id, owner_id: ownerId },
            include: { tasks: true },
        });
        if (!template) {
            throw (0, utils_1.createGeneralError)('Offboarding template not found', 'general', common_1.HttpStatus.NOT_FOUND);
        }
        return template;
    }
    async createCase(data, ownerId, initiatedById) {
        try {
            const member = await this.db.members.findFirst({
                where: { id: data.member_id, owner_id: ownerId },
            });
            if (!member) {
                throw (0, utils_1.createGeneralError)('Member not found', 'general', common_1.HttpStatus.NOT_FOUND);
            }
            const existingCase = await this.db.offboarding_cases.findFirst({
                where: {
                    member_id: data.member_id,
                    status: { not: entities_1.OffboardingCaseStatusEnum.cancelled },
                },
            });
            if (existingCase && existingCase.status !== entities_1.OffboardingCaseStatusEnum.completed) {
                throw (0, utils_1.createGeneralError)('Active offboarding case already exists for this member', 'general', common_1.HttpStatus.CONFLICT);
            }
            const lastWorkingDate = data.last_working_date
                ? new Date(data.last_working_date)
                : new Date(Date.now() + 30 * 24 * 60 * 60 * 1000);
            const offboardingCase = await this.db.runInTransaction(async (manager) => {
                const caseRepo = manager.getRepository('offboarding_cases');
                const taskRepo = manager.getRepository('offboarding_tasks');
                const eqRepo = manager.getRepository('equipment_returns');
                const exitRepo = manager.getRepository('exit_interviews');
                const settlementRepo = manager.getRepository('final_settlements');
                const newCase = caseRepo.create({
                    member_id: data.member_id,
                    template_id: data.template_id || null,
                    initiated_by_id: initiatedById,
                    reason: data.reason || entities_1.OffboardingReasonEnum.resignation,
                    last_working_date: lastWorkingDate,
                    notice_period_days: data.notice_period_days ?? 30,
                    status: entities_1.OffboardingCaseStatusEnum.initiated,
                    notes: data.notes || null,
                    owner_id: ownerId,
                });
                const savedCase = await caseRepo.save(newCase);
                const caseId = savedCase.id;
                let tasksToInsert = [];
                if (data.template_id) {
                    const tpl = await this.db.offboarding_templates.findFirst({
                        where: { id: data.template_id, owner_id: ownerId },
                        include: { tasks: true },
                    });
                    if (tpl && tpl.tasks && tpl.tasks.length > 0) {
                        tasksToInsert = tpl.tasks.map((t, idx) => ({
                            offboarding_case_id: caseId,
                            title: t.title,
                            description: t.description,
                            owner_type: t.owner_type,
                            due_date: new Date(lastWorkingDate.getTime() - (t.relative_due_days || 3) * 24 * 60 * 60 * 1000),
                            priority: t.priority,
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: t.order_index ?? idx,
                        }));
                    }
                }
                if (tasksToInsert.length === 0) {
                    tasksToInsert = [
                        {
                            offboarding_case_id: caseId,
                            title: 'Knowledge Transfer & Handover Documentation',
                            description: 'Handover active projects and responsibilities to designated team member',
                            owner_type: entities_1.TaskOwnerTypeEnum.employee,
                            due_date: new Date(lastWorkingDate.getTime() - 7 * 24 * 60 * 60 * 1000),
                            priority: 'high',
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: 0,
                        },
                        {
                            offboarding_case_id: caseId,
                            title: 'Equipment & Asset Return',
                            description: 'Return company laptop, monitor, peripherals, and building access card',
                            owner_type: entities_1.TaskOwnerTypeEnum.it,
                            due_date: lastWorkingDate,
                            priority: 'high',
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: 1,
                        },
                        {
                            offboarding_case_id: caseId,
                            title: 'Exit Interview Completion',
                            description: 'Complete confidential exit feedback questionnaire',
                            owner_type: entities_1.TaskOwnerTypeEnum.hr,
                            due_date: new Date(lastWorkingDate.getTime() - 3 * 24 * 60 * 60 * 1000),
                            priority: 'medium',
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: 2,
                        },
                        {
                            offboarding_case_id: caseId,
                            title: 'IT & User Access Deactivation',
                            description: 'Revoke company email, VPN, SSO, and internal portal authorization',
                            owner_type: entities_1.TaskOwnerTypeEnum.it,
                            due_date: lastWorkingDate,
                            priority: 'critical',
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: 3,
                        },
                        {
                            offboarding_case_id: caseId,
                            title: 'Final Financial Settlement Approval',
                            description: 'Calculate and approve final salary, leave encashment, and severance',
                            owner_type: entities_1.TaskOwnerTypeEnum.finance,
                            due_date: new Date(lastWorkingDate.getTime() + 3 * 24 * 60 * 60 * 1000),
                            priority: 'high',
                            status: entities_1.TaskStatusEnum.pending,
                            order_index: 4,
                        },
                    ];
                }
                await taskRepo.save(taskRepo.create(tasksToInsert));
                const eqToInsert = [
                    {
                        offboarding_case_id: caseId,
                        item_name: 'Company Laptop / Workstation',
                        item_type: 'hardware',
                        condition: 'good',
                    },
                    {
                        offboarding_case_id: caseId,
                        item_name: 'Building ID Badge & Keycard',
                        item_type: 'access',
                        condition: 'good',
                    },
                ];
                await eqRepo.save(eqRepo.create(eqToInsert));
                await exitRepo.save(exitRepo.create({
                    offboarding_case_id: caseId,
                    member_id: data.member_id,
                    status: 'pending',
                }));
                await settlementRepo.save(settlementRepo.create({
                    offboarding_case_id: caseId,
                    member_id: data.member_id,
                    status: entities_1.SettlementStatusEnum.draft,
                    owner_id: ownerId,
                }));
                return savedCase;
            });
            try {
                await this.notificationsService.sendNotification({
                    owner_id: ownerId,
                    title: 'Offboarding Initiated',
                    message: `Offboarding case initiated for ${member.first_name} ${member.last_name}. Last working day: ${lastWorkingDate.toLocaleDateString()}`,
                    type: 'RECRUITMENT',
                    include_admins: true,
                    reference_id: offboardingCase.id,
                });
            }
            catch (err) {
                config_1.logger.warn('Failed to send offboarding notification', err);
            }
            return this.getCaseById(offboardingCase.id, ownerId);
        }
        catch (error) {
            config_1.logger.error('Failed to create offboarding case', error);
            throw error;
        }
    }
    async getCasesByFilter(query, ownerId) {
        try {
            const page = query.page || 1;
            const limit = query.limit || 10;
            const skip = (page - 1) * limit;
            const where = { owner_id: ownerId };
            if (query.status)
                where.status = query.status;
            if (query.member_id)
                where.member_id = query.member_id;
            const total = await this.db.offboarding_cases.count({ where });
            const items = await this.db.offboarding_cases.findMany({
                where,
                include: {
                    member: { include: { department: true, designation: true } },
                    tasks: true,
                    equipment_returns: true,
                    exit_interview: true,
                    final_settlement: true,
                },
                orderBy: { created_at: 'desc' },
                skip,
                take: limit,
            });
            return {
                data: items,
                pagination: {
                    total,
                    page,
                    limit,
                    totalPages: Math.ceil(total / limit),
                },
            };
        }
        catch (error) {
            config_1.logger.error('Failed to fetch offboarding cases', error);
            throw error;
        }
    }
    async getCaseById(id, ownerId) {
        const offboardingCase = await this.db.offboarding_cases.findFirst({
            where: { id, owner_id: ownerId },
            include: {
                member: { include: { department: true, designation: true, reporting_manager: true } },
                tasks: { include: { assigned_member: true } },
                equipment_returns: true,
                exit_interview: true,
                final_settlement: { include: { items: true } },
            },
        });
        if (!offboardingCase) {
            throw (0, utils_1.createGeneralError)('Offboarding case not found', 'general', common_1.HttpStatus.NOT_FOUND);
        }
        return offboardingCase;
    }
    async updateCase(id, data, ownerId) {
        const currentCase = await this.getCaseById(id, ownerId);
        const updatePayload = { ...data };
        if (data.status === entities_1.OffboardingCaseStatusEnum.completed && currentCase.status !== entities_1.OffboardingCaseStatusEnum.completed) {
            const pendingTasks = (currentCase.tasks || []).filter((t) => t.status === entities_1.TaskStatusEnum.pending || t.status === entities_1.TaskStatusEnum.in_progress);
            if (pendingTasks.length > 0) {
                throw (0, utils_1.createGeneralError)(`Cannot close offboarding case because ${pendingTasks.length} clearance task(s) remain incomplete`, 'general', common_1.HttpStatus.BAD_REQUEST);
            }
            updatePayload.completed_at = new Date();
            if (!currentCase.access_deactivated_at) {
                updatePayload.access_deactivated_at = new Date();
                await this.db.members.update({
                    where: { id: currentCase.member_id },
                    data: { status: entities_1.MemberStatusEnum.deactivated },
                });
            }
        }
        await this.db.offboarding_cases.update({
            where: { id },
            data: updatePayload,
        });
        return this.getCaseById(id, ownerId);
    }
    async addTask(caseId, data, ownerId) {
        await this.getCaseById(caseId, ownerId);
        return await this.db.offboarding_tasks.create({
            data: {
                offboarding_case_id: caseId,
                title: data.title,
                description: data.description,
                owner_type: data.owner_type,
                assigned_member_id: data.assigned_member_id || null,
                due_date: data.due_date ? new Date(data.due_date) : null,
                priority: data.priority,
                status: entities_1.TaskStatusEnum.pending,
                order_index: data.order_index ?? 0,
                notes: data.notes || null,
            },
        });
    }
    async updateTask(taskId, data, ownerId, currentMemberId) {
        const task = await this.db.offboarding_tasks.findFirst({
            where: { id: taskId },
            include: { offboarding_case: true },
        });
        if (!task || task.offboarding_case.owner_id !== ownerId) {
            throw (0, utils_1.createGeneralError)('Offboarding task not found', 'general', common_1.HttpStatus.NOT_FOUND);
        }
        const updatePayload = { ...data };
        if (data.status === entities_1.TaskStatusEnum.completed && task.status !== entities_1.TaskStatusEnum.completed) {
            updatePayload.completed_at = new Date();
            updatePayload.completed_by_id = currentMemberId || null;
            if (task.title.toLowerCase().includes('access') || task.title.toLowerCase().includes('deactivation')) {
                await this.db.members.update({
                    where: { id: task.offboarding_case.member_id },
                    data: { status: entities_1.MemberStatusEnum.deactivated },
                });
                await this.db.offboarding_cases.update({
                    where: { id: task.offboarding_case_id },
                    data: { access_deactivated_at: new Date() },
                });
            }
        }
        await this.db.offboarding_tasks.update({
            where: { id: taskId },
            data: updatePayload,
        });
        return this.db.offboarding_tasks.findFirst({ where: { id: taskId } });
    }
    async addEquipmentReturn(caseId, data, ownerId) {
        await this.getCaseById(caseId, ownerId);
        return await this.db.equipment_returns.create({
            data: {
                offboarding_case_id: caseId,
                item_name: data.item_name,
                item_type: data.item_type,
                serial_number: data.serial_number || null,
                condition: data.condition || 'good',
                notes: data.notes || null,
            },
        });
    }
    async updateEquipmentReturn(returnId, data, ownerId, receiverId) {
        const item = await this.db.equipment_returns.findFirst({
            where: { id: returnId },
            include: { offboarding_case: true },
        });
        if (!item || item.offboarding_case.owner_id !== ownerId) {
            throw (0, utils_1.createGeneralError)('Equipment return item not found', 'general', common_1.HttpStatus.NOT_FOUND);
        }
        const updatePayload = {
            condition: data.condition || item.condition,
            returned_at: data.returned_at ? new Date(data.returned_at) : new Date(),
            received_by_id: receiverId || null,
            notes: data.notes || item.notes,
        };
        await this.db.equipment_returns.update({
            where: { id: returnId },
            data: updatePayload,
        });
        return this.db.equipment_returns.findFirst({ where: { id: returnId } });
    }
    async createExitTemplate(data, ownerId) {
        return await this.db.exit_interview_templates.create({
            data: {
                title: data.title,
                description: data.description,
                is_active: data.is_active ?? true,
                questions: data.questions,
                owner_id: ownerId,
            },
        });
    }
    async getExitTemplates(ownerId) {
        return await this.db.exit_interview_templates.findMany({
            where: { owner_id: ownerId },
            orderBy: { created_at: 'desc' },
        });
    }
    async submitExitInterview(caseId, data, ownerId) {
        const offboardingCase = await this.getCaseById(caseId, ownerId);
        let interview = await this.db.exit_interviews.findFirst({
            where: { offboarding_case_id: caseId },
        });
        if (!interview) {
            interview = await this.db.exit_interviews.create({
                data: {
                    offboarding_case_id: caseId,
                    member_id: offboardingCase.member_id,
                    status: 'completed',
                    submitted_at: new Date(),
                    responses: data.responses,
                    notes: data.notes || null,
                },
            });
        }
        else {
            await this.db.exit_interviews.update({
                where: { id: interview.id },
                data: {
                    status: 'completed',
                    submitted_at: new Date(),
                    responses: data.responses,
                    notes: data.notes || interview.notes,
                },
            });
        }
        return this.db.exit_interviews.findFirst({ where: { offboarding_case_id: caseId } });
    }
    async getTurnoverAnalytics(ownerId) {
        const cases = await this.db.offboarding_cases.findMany({
            where: { owner_id: ownerId },
            include: { member: { include: { department: true } } },
        });
        const totalOffboarded = cases.length;
        const reasonBreakdown = {};
        const departmentBreakdown = {};
        for (const c of cases) {
            const reason = c.reason || 'other';
            reasonBreakdown[reason] = (reasonBreakdown[reason] || 0) + 1;
            const deptName = c.member?.department?.title || 'Unassigned';
            departmentBreakdown[deptName] = (departmentBreakdown[deptName] || 0) + 1;
        }
        return {
            total_offboarded: totalOffboarded,
            reasons_breakdown: reasonBreakdown,
            department_breakdown: departmentBreakdown,
        };
    }
    async calculateFinalSettlement(caseId, data, ownerId) {
        const offboardingCase = await this.getCaseById(caseId, ownerId);
        const grossSalary = data.gross_salary ?? 50000;
        const unusedLeaveDays = data.unused_leave_days ?? 5;
        const dailyRate = data.daily_leave_rate ?? (grossSalary / 30);
        const leaveEncashment = unusedLeaveDays * dailyRate;
        const severance = data.severance_amount ?? 0;
        const noticePay = data.notice_pay_adjustment ?? 0;
        const deductions = data.deductions_amount ?? 0;
        const grossSettlement = grossSalary + leaveEncashment + severance + noticePay;
        const netSettlement = Math.max(0, grossSettlement - deductions);
        const calcDate = new Date();
        let settlement = await this.db.final_settlements.findFirst({
            where: { offboarding_case_id: caseId },
        });
        if (settlement) {
            await this.db.final_settlement_items.delete({ where: { settlement_id: settlement.id } });
            await this.db.final_settlements.update({
                where: { id: settlement.id },
                data: {
                    status: entities_1.SettlementStatusEnum.calculated,
                    calculation_date: calcDate,
                    gross_settlement: grossSettlement,
                    total_deductions: deductions,
                    net_settlement: netSettlement,
                    notes: data.notes || settlement.notes,
                },
            });
        }
        else {
            settlement = await this.db.final_settlements.create({
                data: {
                    offboarding_case_id: caseId,
                    member_id: offboardingCase.member_id,
                    status: entities_1.SettlementStatusEnum.calculated,
                    calculation_date: calcDate,
                    gross_settlement: grossSettlement,
                    total_deductions: deductions,
                    net_settlement: netSettlement,
                    notes: data.notes || null,
                    owner_id: ownerId,
                },
            });
        }
        const settlementId = settlement.id;
        const items = [
            { settlement_id: settlementId, item_name: 'Base Salary (Final Month)', item_type: 'earning', amount: grossSalary },
            { settlement_id: settlementId, item_name: `Unused Leave Encashment (${unusedLeaveDays} days)`, item_type: 'earning', amount: leaveEncashment },
            ...(severance > 0 ? [{ settlement_id: settlementId, item_name: 'Gratuity / Severance Pay', item_type: 'earning', amount: severance }] : []),
            ...(noticePay > 0 ? [{ settlement_id: settlementId, item_name: 'Notice Period Adjustment', item_type: 'earning', amount: noticePay }] : []),
            ...(deductions > 0 ? [{ settlement_id: settlementId, item_name: 'Company Deductions / Loan Clearance', item_type: 'deduction', amount: deductions }] : []),
        ];
        for (const item of items) {
            await this.db.final_settlement_items.create({ data: item });
        }
        return this.db.final_settlements.findFirst({
            where: { id: settlementId },
            include: { items: true },
        });
    }
    async approveFinalSettlement(settlementId, ownerId, approverId) {
        const settlement = await this.db.final_settlements.findFirst({
            where: { id: settlementId, owner_id: ownerId },
        });
        if (!settlement) {
            throw (0, utils_1.createGeneralError)('Final settlement record not found', 'general', common_1.HttpStatus.NOT_FOUND);
        }
        if (settlement.status === entities_1.SettlementStatusEnum.approved || settlement.status === entities_1.SettlementStatusEnum.included_in_payroll) {
            throw (0, utils_1.createGeneralError)('Settlement is already approved', 'general', common_1.HttpStatus.BAD_REQUEST);
        }
        await this.db.final_settlements.update({
            where: { id: settlementId },
            data: {
                status: entities_1.SettlementStatusEnum.approved,
                approved_at: new Date(),
                approved_by_id: approverId,
            },
        });
        return this.db.final_settlements.findFirst({
            where: { id: settlementId },
            include: { items: true },
        });
    }
    async getDashboardStats(ownerId) {
        const activeCases = await this.db.offboarding_cases.count({
            where: { owner_id: ownerId, status: entities_1.OffboardingCaseStatusEnum.in_progress },
        });
        const initiatedCases = await this.db.offboarding_cases.count({
            where: { owner_id: ownerId, status: entities_1.OffboardingCaseStatusEnum.initiated },
        });
        const pendingSettlements = await this.db.final_settlements.count({
            where: { owner_id: ownerId, status: entities_1.SettlementStatusEnum.calculated },
        });
        const completedCases = await this.db.offboarding_cases.count({
            where: { owner_id: ownerId, status: entities_1.OffboardingCaseStatusEnum.completed },
        });
        return {
            active_cases: activeCases,
            initiated_cases: initiatedCases,
            pending_settlements: pendingSettlements,
            completed_cases: completedCases,
        };
    }
};
exports.OffboardingService = OffboardingService;
exports.OffboardingService = OffboardingService = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [config_1.DatabaseService,
        notifications_service_1.NotificationsService])
], OffboardingService);
//# sourceMappingURL=offboarding.service.js.map