import { AXPSystemStatuses } from '@acorex/platform/common';
import { AXPEntityService } from '@acorex/platform/layout/entity';
import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { RootConfig } from './acorex-modules-human-capital-management.mjs';

//#endregion
/**
 * Reject Leave Request Command
 * Updates the leave request status to Rejected
 */
class RejectLeaveRequestCommand {
    constructor() {
        //#region ----   Services   ----
        this.entityService = inject(AXPEntityService);
    }
    //#endregion
    //#region ----   Command Implementation   ----
    async execute(input) {
        try {
            console.log('[RejectLeaveRequestCommand] Executing with input:', input);
            const dataAccessor = this.entityService
                .withEntity(RootConfig.module.name, RootConfig.entities.leaveRequest.name)
                .data();
            // Update the leave request status to Rejected
            const updateData = {
                statusId: AXPSystemStatuses.Rejected.name,
            };
            // Add reason/note if provided (these fields might not exist in entity model)
            if (input.reason) {
                updateData.reason = input.reason;
            }
            if (input.note) {
                updateData.note = input.note;
            }
            console.log('[RejectLeaveRequestCommand] Updating entity with:', updateData);
            await dataAccessor.update(input.id, updateData);
            console.log('[RejectLeaveRequestCommand] Update successful');
            return {
                success: true,
            };
        }
        catch (error) {
            console.error('[RejectLeaveRequestCommand] Error:', error);
            return {
                success: false,
                message: {
                    text: error.message || 'Failed to reject leave request',
                },
            };
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: RejectLeaveRequestCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: RejectLeaveRequestCommand, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: RejectLeaveRequestCommand, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

export { RejectLeaveRequestCommand };
//# sourceMappingURL=acorex-modules-human-capital-management-reject-leave-request.command-Dg45oY0X.mjs.map
