import { AXMEntityCrudServiceImpl } from '@acorex/platform/layout/entity';
import * as i0 from '@angular/core';
import { inject, Injector, runInInjectionContext, Injectable } from '@angular/core';

class AXCDistributionCommand {
    constructor() {
        this.injector = inject(Injector);
    }
    async execute(input) {
        const dataService = runInInjectionContext(this.injector, () => new AXMEntityCrudServiceImpl(`${input.refType}Distribution`));
        const dataServiceEntity = runInInjectionContext(this.injector, () => new AXMEntityCrudServiceImpl(input.refType));
        try {
            for (const user of input.assignedTo) {
                await dataService.insertOne({
                    distributionRefId: input.refId,
                    assignedId: user,
                    distributionDate: new Date(),
                });
                await dataServiceEntity.updateOne(input.refId, {
                    stateInfo: {
                        ...(await dataServiceEntity.getOne(input.refId)).stateInfo,
                        isDistributed: true,
                    },
                });
            }
            return {
                success: true,
                data: {
                    success: true,
                    message: 'Distribution records created successfully',
                },
            };
        }
        catch (error) {
            return {
                success: false,
                message: {
                    text: error instanceof Error ? error.message : 'Failed to create distribution records',
                },
                data: {
                    success: false,
                    message: 'Failed to create distribution records',
                },
            };
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXCDistributionCommand, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXCDistributionCommand, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXCDistributionCommand, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

export { AXCDistributionCommand };
//# sourceMappingURL=acorex-connectivity-mock-distribution-record.command-BopU0LyU.mjs.map
