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
/**
 * Cancel Leave Request Command
 * Updates the leave request status to Cancelled
 */
class CancelLeaveRequestCommand {
    constructor() {
        //#region ----   Services   ----
        this.entityService = inject(AXPEntityService);
    }
    //#endregion
    //#region ----   Command Implementation   ----
    async execute(input) {
        try {
            const dataAccessor = this.entityService
                .withEntity(RootConfig.module.name, RootConfig.entities.leaveRequest.name)
                .data();
            // Update the leave request status to Cancelled
            const updateData = {
                statusId: AXPSystemStatuses.Cancelled.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;
            }
            await dataAccessor.update(input.id, updateData);
            return {
                success: true,
            };
        }
        catch (error) {
            console.error('[CancelLeaveRequestCommand] Error:', error);
            return {
                success: false,
                message: {
                    text: error.message || 'Failed to cancel leave request',
                },
            };
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CancelLeaveRequestCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CancelLeaveRequestCommand, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: CancelLeaveRequestCommand, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

export { CancelLeaveRequestCommand };
//# sourceMappingURL=acorex-modules-human-capital-management-cancel-leave-request.command-iGNY2Pxh.mjs.map
