import * as i0 from '@angular/core';
import { inject, Injector, Injectable, NgModule } from '@angular/core';
import { AXP_PERMISSION_DEFINITION_PROVIDER } from '@acorex/platform/auth';
import { AXP_MENU_PROVIDER, AXP_SEARCH_PROVIDER, AXPSearchCommandProvider, createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXP_MODULE_MANIFEST_PROVIDER, provideLazyProvider } from '@acorex/platform/core';
import { AXMEntityCrudServiceImpl, AXP_ENTITY_DEFINITION_LOADER, AXPEntityService, entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig as RootConfig$1 } from '@acorex/modules/human-capital-management';
import { AXPWidgetsList } from '@acorex/modules/common';
import { RootConfig as RootConfig$2 } from '@acorex/modules/assessment-management';

//#region ----   Root Configuration   ----
const config = {
    i18n: 'maintenance-management',
    module: 'MaintenanceManagement',
    route: 'maintenance-management',
};
const RootConfig = {
    config,
    module: {
        route: config.route,
        name: config.module,
        title: '@maintenance-management:module.title',
        icon: 'fa-light fa-box',
    },
    entities: {
        maintenance: {
            name: 'Maintenance',
            source: `${config.module}.Maintenance`,
            title: '@maintenance-management:maintenances.entities.maintenance.title',
            titlePlural: '@maintenance-management:maintenances.entities.maintenance.plural',
            icon: 'fa-light fa-clipboard-list',
        },
        maintenanceType: {
            name: 'MaintenanceType',
            source: `${config.module}.MaintenanceType`,
            title: '@maintenance-management:maintenance-types.entities.maintenance-type.title',
            titlePlural: '@maintenance-management:maintenance-types.entities.maintenance-type.plural',
            icon: 'fa-light fa-tags',
        },
    },
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Provider   ----
class AXMMaintenanceManagementEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    async get(moduleName, entityName) {
        if (moduleName === RootConfig.module.name) {
            switch (entityName) {
                case RootConfig.entities.maintenance.name:
                    return (await Promise.resolve().then(function () { return maintenance_entity; })).factory(this.injector);
                case RootConfig.entities.maintenanceType.name:
                    return (await Promise.resolve().then(function () { return maintenanceType_entity; })).factory(this.injector);
            }
        }
        return null;
    }
    async list() {
        const m = RootConfig.module.name;
        return Promise.resolve(Object.values(RootConfig.entities).map((e) => ({ name: e.name, module: m })));
    }
}
//#endregion

var entity_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMMaintenanceManagementEntityProvider: AXMMaintenanceManagementEntityProvider
});

const AXMMaintenanceManagementFeatureKeys = {
    Management: 'MaintenanceManagement:Feature:Management',
};

//#region ----   Imports   ----
//#endregion
//#region ----   Service   ----
class AXMMaintenanceManagementMaintenanceEntityService extends AXMEntityCrudServiceImpl {
}
class AXMMaintenanceManagementMaintenanceEntityServiceImpl extends AXMMaintenanceManagementMaintenanceEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.maintenance.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

//#region ----   Imports   ----
//#endregion
//#region ----   Module   ----
class AXMMaintenanceManagementMaintenanceEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityModule, providers: [
            {
                provide: AXMMaintenanceManagementMaintenanceEntityService,
                useClass: AXMMaintenanceManagementMaintenanceEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    providers: [
                        {
                            provide: AXMMaintenanceManagementMaintenanceEntityService,
                            useClass: AXMMaintenanceManagementMaintenanceEntityServiceImpl,
                        },
                    ],
                }]
        }] });

//#region ----   Imports   ----
//#endregion
//#region ----   Service   ----
class AXMMaintenanceManagementMaintenanceTypeEntityService extends AXMEntityCrudServiceImpl {
}
class AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl extends AXMMaintenanceManagementMaintenanceTypeEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.maintenanceType.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

//#region ----   Imports   ----
//#endregion
//#region ----   Module   ----
class AXMMaintenanceManagementMaintenanceTypeEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityModule, providers: [
            {
                provide: AXMMaintenanceManagementMaintenanceTypeEntityService,
                useClass: AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementMaintenanceTypeEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    providers: [
                        {
                            provide: AXMMaintenanceManagementMaintenanceTypeEntityService,
                            useClass: AXMMaintenanceManagementMaintenanceTypeEntityServiceImpl,
                        },
                    ],
                }]
        }] });

//#region ----   Imports   ----
//#endregion
//#region ----   Manifest Definition   ----
/**
 * Maintenance Management Module Manifest.
 * Defines module metadata, features, and provider references.
 */
const MaintenanceManagementManifest = {
    name: RootConfig.module.name,
    version: '1.0.0',
    title: RootConfig.module.title,
    icon: RootConfig.module.icon,
    i18n: RootConfig.config.i18n,
    required: false,
    // Module dependencies (optional)
};
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Module   ----
class AXMMaintenanceManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementModule, imports: [AXMMaintenanceManagementMaintenanceEntityModule,
            AXMMaintenanceManagementMaintenanceTypeEntityModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementModule, providers: [
            // Module Manifest Provider
            {
                provide: AXP_MODULE_MANIFEST_PROVIDER,
                useValue: MaintenanceManagementManifest,
                multi: true,
            },
            // Provider references (now using tokens)
            provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then((m) => m.AXMMaintenanceManagementPermissionDefinitionProvider)),
            provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then((m) => m.AXMMaintenanceManagementMenuProvider)),
            provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then((m) => m.AXMMaintenanceManagementEntityProvider)),
            provideLazyProvider(AXP_SEARCH_PROVIDER, () => Promise.resolve().then(function () { return search_provider; }).then((m) => m.AXMMaintenanceManagementSearchCommandProvider)),
        ], imports: [AXMMaintenanceManagementMaintenanceEntityModule,
            AXMMaintenanceManagementMaintenanceTypeEntityModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: AXMMaintenanceManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        AXMMaintenanceManagementMaintenanceEntityModule,
                        AXMMaintenanceManagementMaintenanceTypeEntityModule,
                    ],
                    providers: [
                        // Module Manifest Provider
                        {
                            provide: AXP_MODULE_MANIFEST_PROVIDER,
                            useValue: MaintenanceManagementManifest,
                            multi: true,
                        },
                        // Provider references (now using tokens)
                        provideLazyProvider(AXP_PERMISSION_DEFINITION_PROVIDER, () => Promise.resolve().then(function () { return permissionDefinition_provider; }).then((m) => m.AXMMaintenanceManagementPermissionDefinitionProvider)),
                        provideLazyProvider(AXP_MENU_PROVIDER, () => Promise.resolve().then(function () { return menu_provider; }).then((m) => m.AXMMaintenanceManagementMenuProvider)),
                        provideLazyProvider(AXP_ENTITY_DEFINITION_LOADER, () => Promise.resolve().then(function () { return entity_provider; }).then((m) => m.AXMMaintenanceManagementEntityProvider)),
                        provideLazyProvider(AXP_SEARCH_PROVIDER, () => Promise.resolve().then(function () { return search_provider; }).then((m) => m.AXMMaintenanceManagementSearchCommandProvider)),
                    ],
                }]
        }] });

const AXMMaintenanceManagementMenuKeys = {
    Root: 'MaintenanceManagement:Menu',
    Maintenances: 'MaintenanceManagement:Menu:Maintenances',
    MaintenanceTypes: 'MaintenanceManagement:Menu:MaintenanceTypes',
};

const AXMMaintenanceManagementPermissionKeys = {
    MaintenanceManagement: {
        Management: 'MaintenanceManagement:Permission:MaintenanceManagement.Management',
        MaintenanceType: {
            Management: 'MaintenanceManagement:Permission:MaintenanceType.Management',
            View: 'MaintenanceManagement:Permission:MaintenanceType.View',
            Create: 'MaintenanceManagement:Permission:MaintenanceType.Create',
            Update: 'MaintenanceManagement:Permission:MaintenanceType.Update',
            Delete: 'MaintenanceManagement:Permission:MaintenanceType.Delete',
        },
        Maintenance: {
            Management: 'MaintenanceManagement:Permission:Maintenance.Management',
            View: 'MaintenanceManagement:Permission:Maintenance.View',
            Create: 'MaintenanceManagement:Permission:Maintenance.Create',
            Update: 'MaintenanceManagement:Permission:Maintenance.Update',
            Delete: 'MaintenanceManagement:Permission:Maintenance.Delete',
        },
    },
};

//#region ----   Imports   ----
//#endregion
//#region ----   Menu Provider   ----
/**
 * Maintenance Management Menu Provider.
 * Provides menu items for the Maintenance Management module with permission and feature checks.
 */
class AXMMaintenanceManagementMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const module = RootConfig.module;
        const keys = AXMMaintenanceManagementPermissionKeys.MaintenanceManagement;
        context.addItems([
            {
                name: AXMMaintenanceManagementMenuKeys.Root,
                priority: 9050,
                text: module.title,
                icon: module.icon,
                policy: {
                    features: [module.name],
                },
                children: [
                    // {
                    //   name: AXMMaintenanceManagementMenuKeys.Maintenances,
                    //   text: RootConfig.entities.maintenance.titlePlural,
                    //   icon: RootConfig.entities.maintenance.icon,
                    //   path: this.entityService.createPath(module.name, RootConfig.entities.maintenance.name),
                    //   priority: 1,
                    //   policy: {
                    //     permissions: [keys.Maintenance.View],
                    //   },
                    // },
                    {
                        name: AXMMaintenanceManagementMenuKeys.MaintenanceTypes,
                        text: RootConfig.entities.maintenanceType.titlePlural,
                        icon: RootConfig.entities.maintenanceType.icon,
                        path: this.entityService.createPath(module.name, RootConfig.entities.maintenanceType.name),
                        priority: 2,
                        policy: {
                            permissions: [keys.MaintenanceType.View],
                        },
                    },
                ],
            },
        ]);
    }
}
//#endregion

var menu_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMMaintenanceManagementMenuProvider: AXMMaintenanceManagementMenuProvider
});

//#region ----   Imports   ----
//#endregion
//#region ----   Permission Definition Provider   ----
class AXMMaintenanceManagementPermissionDefinitionProvider {
    async define(context) {
        const keys = AXMMaintenanceManagementPermissionKeys.MaintenanceManagement;
        // I18n path constants for cleaner code
        const MODULE_PERMISSIONS = '@maintenance-management:module.permissions';
        const MAINTENANCE_TYPES_PERMISSIONS = '@maintenance-management:maintenance-types.permissions';
        const MAINTENANCES_PERMISSIONS = '@maintenance-management:maintenances.permissions';
        context
            .addGroup(keys.Management, `${MODULE_PERMISSIONS}.title`, `${MODULE_PERMISSIONS}.description`)
            .addPermission(keys.MaintenanceType.Management, `${MAINTENANCE_TYPES_PERMISSIONS}.manage.title`, `${MAINTENANCE_TYPES_PERMISSIONS}.manage.description`)
            .addChild(keys.MaintenanceType.View, `${MAINTENANCE_TYPES_PERMISSIONS}.view.title`, `${MAINTENANCE_TYPES_PERMISSIONS}.view.description`)
            .addChild(keys.MaintenanceType.Create, `${MAINTENANCE_TYPES_PERMISSIONS}.create.title`, `${MAINTENANCE_TYPES_PERMISSIONS}.create.description`)
            .addChild(keys.MaintenanceType.Update, `${MAINTENANCE_TYPES_PERMISSIONS}.edit.title`, `${MAINTENANCE_TYPES_PERMISSIONS}.edit.description`)
            .addChild(keys.MaintenanceType.Delete, `${MAINTENANCE_TYPES_PERMISSIONS}.delete.title`, `${MAINTENANCE_TYPES_PERMISSIONS}.delete.description`)
            .endPermission()
            .addPermission(keys.Maintenance.Management, `${MAINTENANCES_PERMISSIONS}.manage.title`, `${MAINTENANCES_PERMISSIONS}.manage.description`)
            .addChild(keys.Maintenance.View, `${MAINTENANCES_PERMISSIONS}.view.title`, `${MAINTENANCES_PERMISSIONS}.view.description`)
            .addChild(keys.Maintenance.Create, `${MAINTENANCES_PERMISSIONS}.create.title`, `${MAINTENANCES_PERMISSIONS}.create.description`)
            .addChild(keys.Maintenance.Update, `${MAINTENANCES_PERMISSIONS}.edit.title`, `${MAINTENANCES_PERMISSIONS}.edit.description`)
            .addChild(keys.Maintenance.Delete, `${MAINTENANCES_PERMISSIONS}.delete.title`, `${MAINTENANCES_PERMISSIONS}.delete.description`)
            .endPermission()
            .endGroup();
    }
}
//#endregion

var permissionDefinition_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMMaintenanceManagementPermissionDefinitionProvider: AXMMaintenanceManagementPermissionDefinitionProvider
});

//#region ----   Imports   ----
//#endregion
//#region ----   Search Provider   ----
class AXMMaintenanceManagementSearchCommandProvider extends AXPSearchCommandProvider {
    constructor() {
        super(...arguments);
        this.commands = [
            {
                group: 'entity',
                title: '@maintenance-management:maintenances.search.create-maintenance.title',
                icon: RootConfig.entities.maintenance.icon,
                description: '@maintenance-management:maintenances.search.create-maintenance.description',
                command: {
                    name: 'create-entity',
                    options: {
                        entity: `${RootConfig.module.name}.${RootConfig.entities.maintenance.name}`,
                    },
                },
            },
        ];
    }
}
//#endregion

var search_provider = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMMaintenanceManagementSearchCommandProvider: AXMMaintenanceManagementSearchCommandProvider
});

//#region ----   Types   ----
var AXMPerformedBy;
(function (AXMPerformedBy) {
    AXMPerformedBy["Employee"] = "employee";
    AXMPerformedBy["ThirdParty"] = "thirdParty";
})(AXMPerformedBy || (AXMPerformedBy = {}));
const idAXPMetaData = AXMPerformedBy.Employee;
//#endregion

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function factory$1(injector) {
    const dataService = injector.get(AXMMaintenanceManagementMaintenanceEntityService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.maintenance.name,
        title: RootConfig.entities.maintenance.title,
        icon: RootConfig.entities.maintenance.icon,
        plugins: [
            { name: 'archive', options: { order: 1 } },
            { name: 'history', options: { order: 2 } },
            // {
            //   name: 'category',
            //   options: {
            //     appearance: { icon: true, color: true },
            //     metaData: { enabled: true },
            //   }
            // },
            {
                name: 'meta-data-form',
                options: {
                    path: 'maintenanceTypeId',
                    title: '@maintenance-management:maintenances.entities.maintenance.components.meta-data-form.title',
                },
            },
            { name: 'notes', options: { order: 5 } },
            { name: 'attachments', options: { order: 6 } },
        ],
        formats: {
            individual: RootConfig.entities.maintenance.title,
            plural: RootConfig.entities.maintenance.titlePlural,
            searchResult: { title: '{{ title }}', description: RootConfig.module.title },
        },
        groups: [
            { id: 'basic-info', title: '@maintenance-management:maintenances.entities.maintenance.groups.basic-info' },
            { id: 'performed-by', title: '@maintenance-management:maintenances.entities.maintenance.groups.performed-by' },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'resourceEntityId',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.resource-entity-id',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    visible: false,
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'entity',
                            textField: 'title',
                            allowSearch: true,
                            dataSource: 'entities'
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'resourceId',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.resource-id.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    readonly: true,
                    //readonly: `{{ !!context.eval('resourceId') }}`,
                    visible: false,
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {},
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            // {
            //   name: 'resourceId',
            //   title: '@maintenance-management:maintenances.entities.maintenance.fields.resource-id.title',
            //   groupId: 'basic-info',
            //   schema: {
            //     dataType: 'string',
            //     readonly : true , 
            //     //readonly: `{{ !!context.eval('resourceId') }}`,
            //     // visible: false,
            //     interface: {
            //       type: AXPWidgetsCatalog.lookup,
            //       options: {
            //         readonly : true ,
            //         entity: `${RootConfigAsset.module.name}.${RootConfigAsset.entities.asset.name}`,
            //         textField: 'title',
            //         valueField: 'id',
            //         columns: ['code', 'title'],
            //         expose: [
            //           { source: 'id', target: 'resource.id' },
            //           { source: 'title', target: 'resource.title' },
            //           { source: 'code', target: 'resource.code' },
            //           { source: 'availableMaintenanceTypeIds', target: 'resource.availableMaintenanceTypeIds' },
            //         ],
            //       },
            //     },
            //   },
            //   options: {
            //     sort: { enabled: true },
            //     filter: { advance: { enabled: true }, inline: { enabled: true } },
            //   },
            //   validations: [{ rule: 'required' }],
            // },
            {
                name: 'maintenanceTypeId',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.maintenance-type-id.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.maintenanceType.name}`,
                            textField: 'title',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'maintenanceType.id' },
                                { source: 'title', target: 'maintenanceType.title' },
                            ],
                            filter: `{{ context.eval("resource.availableMaintenanceTypeIds")?.length ? { logic: 'and', filters: [{ field: 'id', operator: { type: 'in' }, value: context.eval("resource.availableMaintenanceTypeIds") }] } : null }}`,
                            triggers: [
                                {
                                    event: "{{ events.context('resourceId') }}",
                                    action: '{{ console.log("[maintenanceType trigger] resourceId:", context.eval("resourceId"), "| availableMaintenanceTypeIds:", context.eval("resource.availableMaintenanceTypeIds"), "| full resource:", context.eval("resource")); widget.setValue(null); widget.refresh() }}',
                                },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'performedBy',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.performed-by.title',
                groupId: 'performed-by',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            dataSource: [
                                {
                                    value: AXMPerformedBy.Employee,
                                    text: '@maintenance-management:maintenances.entities.maintenance.fields.performed-by.options.employee',
                                },
                                {
                                    value: AXMPerformedBy.ThirdParty,
                                    text: '@maintenance-management:maintenances.entities.maintenance.fields.performed-by.options.thirdParty',
                                },
                            ],
                        },
                        triggers: [
                            {
                                event: "{{ events.context('performedBy') }}",
                                action: `{{ if(context.eval('performedBy') == '${AXMPerformedBy.Employee}') { context.set('employeeId', context.eval('employeeId')); context.set('thirdPartyId', null); } else if(context.eval('performedBy') == '${AXMPerformedBy.ThirdParty}') { context.set('thirdPartyId', context.eval('thirdPartyId')); context.set('employeeId', null); } }}`,
                            },
                        ],
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'employeeId',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.employee-id.title',
                groupId: 'performed-by',
                schema: {
                    dataType: 'string',
                    visible: `{{ context.eval('performedBy')?.value == '${AXMPerformedBy.Employee}' }}`,
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$1.module.name}.${RootConfig$1.entities.employee.name}`,
                            textField: 'person.displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'employee.id' },
                                { source: 'person.displayName', target: 'employee.displayName' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                // validations: [
                //   { rule: 'required', options: `{{ context.eval('performedBy').value == '${AXMPerformedBy.Employee}' }}` },
                // ],
            },
            {
                name: 'thirdPartyId',
                title: '@maintenance-management:maintenances.entities.maintenance.fields.third-party-id.title',
                groupId: 'performed-by',
                schema: {
                    dataType: 'string',
                    visible: `{{context.eval('performedBy')?.value == '${AXMPerformedBy.ThirdParty}'}}`,
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: 'PersonManagement.Person',
                            textField: 'displayName',
                            valueField: 'id',
                            look: 'select',
                            expose: [
                                { source: 'id', target: 'thirdParty.id' },
                                { source: 'displayName', target: 'thirdParty.displayName' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                // validations: [
                //   { rule: 'required', options: `{{ context.eval('performedBy').value == '${AXMPerformedBy.ThirdParty}' }}` },
                // ],
            },
        ],
        columns: [
            // { name: 'resourceId', options: { dataPath: 'asset.title' } }, //////???????
            { name: 'maintenanceTypeId', options: { dataPath: 'maintenanceType.title' } },
            { name: 'performedBy' },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' }, { id: 'performed-by' }, { id: 'additional' }],
                    properties: [
                        { name: 'resourceId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'maintenanceTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'performedBy', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'thirdPartyId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' }, { id: 'performed-by' }, { id: 'additional' }],
                    properties: [
                        { name: 'resourceId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'maintenanceTypeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'performedBy', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'thirdPartyId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{ maintenance.title }}',
                    sections: [
                        { id: 'basic-info', order: 1 },
                        { id: 'performed-by', order: 2 },
                    ],
                    properties: [
                        { name: 'resourceId', layout: { positions: { lg: { colSpan: 6, order: 1 } } } },
                        { name: 'maintenanceTypeId', layout: { positions: { lg: { colSpan: 6, order: 2 } } } },
                        { name: 'performedBy', layout: { positions: { lg: { colSpan: 6, order: 3 } } } },
                        { name: 'employeeId', layout: { positions: { lg: { colSpan: 6, order: 4 } } } },
                        { name: 'thirdPartyId', layout: { positions: { lg: { colSpan: 6, order: 5 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'resourceId', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

var maintenance_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    factory: factory$1
});

//#region ----   Types   ----
//#endregion

async function factory(injector) {
    const dataService = injector.get(AXMMaintenanceManagementMaintenanceTypeEntityService);
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.maintenanceType.name,
        title: RootConfig.entities.maintenanceType.title,
        icon: RootConfig.entities.maintenanceType.icon,
        plugins: [{ name: 'meta-data-selector' }],
        formats: {
            individual: RootConfig.entities.maintenanceType.title,
            plural: RootConfig.entities.maintenanceType.titlePlural,
            searchResult: { title: '{{ title }}', description: RootConfig.module.title },
        },
        groups: [
            {
                id: 'basic-info',
                title: '@maintenance-management:maintenance-types.entities.maintenance-type.groups.basic-info',
            },
            {
                id: 'questionnary-info',
                title: '@maintenance-management:maintenance-types.entities.maintenance-type.groups.questionnary-info',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'name',
                title: '@maintenance-management:maintenance-types.entities.maintenance-type.fields.name.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@maintenance-management:maintenance-types.entities.maintenance-type.fields.name.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'title',
                title: '@maintenance-management:maintenance-types.entities.maintenance-type.fields.title.title',
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@maintenance-management:maintenance-types.entities.maintenance-type.fields.title.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'questionnaireId',
                title: '@maintenance-management:maintenance-types.entities.maintenance-type.fields.questionnaire-id.title',
                groupId: 'questionnary-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig$2.module.name}.${RootConfig$2.entities.questionnaire.name}`,
                            textField: 'title',
                            valueField: 'id',
                            expose: [
                                { source: 'id', target: 'questionnaire.id' },
                                { source: 'title', target: 'questionnaire.title' },
                            ],
                        },
                    },
                },
            },
        ],
        columns: [{ name: 'name', options: { order: 1 } },
            { name: 'title', options: { order: 2 } },
            { name: 'questionnaireId', options: { dataPath: 'questionnaire.title', order: 3 } }],
        commands: {
            create: {
                execute: async (data) => {
                    return { id: await dataService.insertOne(data) };
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query({
                        skip: e.skip,
                        take: e.take,
                        filter: e.filter,
                        sort: e.sort,
                    });
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'basic-info' },
                        { id: 'questionnary-info' }],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-info' },
                        { id: 'questionnary-info' }],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [{ id: 'basic-info' },
                        { id: 'questionnary-info' }],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'questionnaireId', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'title', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

var maintenanceType_entity = /*#__PURE__*/Object.freeze({
    __proto__: null,
    factory: factory
});

/**
 * Generated bundle index. Do not edit.
 */

export { AXMMaintenanceManagementEntityProvider, AXMMaintenanceManagementFeatureKeys, AXMMaintenanceManagementMenuKeys, AXMMaintenanceManagementMenuProvider, AXMMaintenanceManagementModule, AXMMaintenanceManagementPermissionDefinitionProvider, AXMMaintenanceManagementPermissionKeys, AXMMaintenanceManagementSearchCommandProvider, AXMPerformedBy, RootConfig, idAXPMetaData, factory$1 as maintenanceEntityFactory, factory as maintenanceTypeEntityFactory };
//# sourceMappingURL=acorex-modules-maintenance-management.mjs.map
