import { createAllQueryView, AXPEntityQueryType, AXP_MENU_PROVIDER } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXMEntityCrudServiceImpl, entityMasterCrudActions, entityMasterRecordActions, AXPEntityService, AXP_ENTITY_DEFINITION_LOADER } from '@acorex/platform/layout/entity';
import * as i0 from '@angular/core';
import { Injectable, NgModule, inject, Injector } from '@angular/core';

const config = {
    i18n: 'scheduler-job-management',
};
const RootConfig = {
    config,
    module: {
        route: 'scheduler-job-management',
        name: 'schedulerJobManagement',
        title: `t('module-name', {scope:"${config.i18n}"})`,
        icon: 'fa-light fa-file-invoice',
    },
    entities: {
        schedulerJob: {
            name: 'SchedulerJob',
            title: `t("schedulerJob", { scope: "${config.i18n}" })`,
            icon: 'fa-light fa-list',
        },
    },
};

class AXMSchedulerJobManagementSchedulerJobEntityService extends AXMEntityCrudServiceImpl {
}
class AXMSchedulerJobManagementSchedulerJobEntityServiceImpl extends AXMSchedulerJobManagementSchedulerJobEntityService {
    constructor() {
        super(`${RootConfig.module.name}.${RootConfig.entities.schedulerJob.name}`);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl, decorators: [{
            type: Injectable
        }], ctorParameters: () => [] });

async function schedulerJobFactory(injector) {
    const dataService = injector.get(AXMSchedulerJobManagementSchedulerJobEntityService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.schedulerJob.name,
        title: RootConfig.entities.schedulerJob.title,
        icon: RootConfig.entities.schedulerJob.icon,
        formats: {
            individual: `t("schedulerJob" , { scope : "${i18n}" })`,
            plural: `t("schedulerJobPlural" , { scope : "${i18n}" })`,
        },
        relatedEntities: [],
        groups: [
            {
                id: 'section',
                title: `t("schedulerJob", { scope: "${i18n}" })`,
            },
        ],
        properties: [
            {
                name: 'name',
                title: `t("name", { scope: "${i18n}" })`,
                groupId: 'section',
                options: {
                    sort: {
                        enabled: true,
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'title',
                title: `t("title", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'process',
                title: `t("process", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'value',
                            textField: 'title',
                            defaultValue: '10',
                            dataSource: [
                                { value: 'backup', title: 'Backup' },
                                { value: 'cancelOrder', title: 'Auto Canceling Order' },
                            ],
                            multiple: false,
                        },
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'trigger',
                title: `t("trigger", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.cronJob,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
        ],
        columns: [{ name: 'name' }, { name: 'title' }, { name: 'process' }, { name: 'trigger' }],
        commands: {
            create: {
                execute: async (data) => {
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'section',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'process',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'trigger',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'section',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'process',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                        {
                            name: 'trigger',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'section',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'process',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'trigger',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView()],
                },
            },
        },
    };
    return entityDef;
}

class AXMSchedulerJobManagementSchedulerJobEntityModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityModule }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityModule, providers: [
            {
                provide: AXMSchedulerJobManagementSchedulerJobEntityService,
                useClass: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl,
            },
        ] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementSchedulerJobEntityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXMSchedulerJobManagementSchedulerJobEntityService,
                            useClass: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl,
                        },
                    ],
                }]
        }] });

var index = /*#__PURE__*/Object.freeze({
    __proto__: null,
    AXMSchedulerJobManagementSchedulerJobEntityModule: AXMSchedulerJobManagementSchedulerJobEntityModule,
    AXMSchedulerJobManagementSchedulerJobEntityService: AXMSchedulerJobManagementSchedulerJobEntityService,
    AXMSchedulerJobManagementSchedulerJobEntityServiceImpl: AXMSchedulerJobManagementSchedulerJobEntityServiceImpl,
    schedulerJobFactory: schedulerJobFactory
});

class AXMSchedulerJobManagementModuleEntityProvider {
    constructor() {
        this.injector = inject(Injector);
    }
    async get(moduleName, entityName) {
        if (moduleName == 'scheduler-job-management') {
            switch (entityName) {
                case RootConfig.entities.schedulerJob.name: {
                    const entity = (await Promise.resolve().then(function () { return index; })).schedulerJobFactory;
                    return entity(this.injector);
                }
            }
        }
        return null;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModuleEntityProvider, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModuleEntityProvider }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModuleEntityProvider, decorators: [{
            type: Injectable
        }] });

class AXMSchedulerJobManagementModuleMenuProvider {
    constructor() {
        this.entityService = inject(AXPEntityService);
    }
    async provide(context) {
        const scope = RootConfig.config.i18n;
        const module = RootConfig.module;
        context.addItems([
            {
                priority: 9001,
                text: `t('module-name', {scope: "${scope}"})`,
                icon: module.icon,
                data: {
                //  requiredPermission: 'demo.admin.settings',
                },
                children: [
                    {
                        text: `t('schedulerJobEntity', {scope: "${scope}"})`,
                        path: this.entityService.createPath(module.name, RootConfig.entities.schedulerJob.name),
                        icon: RootConfig.entities.schedulerJob.icon,
                        priority: 1,
                    },
                ],
            },
        ]);
    }
}

class AXMSchedulerJobManagementModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModule, imports: [AXMSchedulerJobManagementSchedulerJobEntityModule] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModule, providers: [
            {
                provide: AXP_MENU_PROVIDER,
                useClass: AXMSchedulerJobManagementModuleMenuProvider,
                multi: true,
            },
            {
                provide: AXP_ENTITY_DEFINITION_LOADER,
                useClass: AXMSchedulerJobManagementModuleEntityProvider,
                multi: true,
            },
        ], imports: [AXMSchedulerJobManagementSchedulerJobEntityModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImport: i0, type: AXMSchedulerJobManagementModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [AXMSchedulerJobManagementSchedulerJobEntityModule,],
                    exports: [],
                    declarations: [],
                    providers: [
                        {
                            provide: AXP_MENU_PROVIDER,
                            useClass: AXMSchedulerJobManagementModuleMenuProvider,
                            multi: true,
                        },
                        {
                            provide: AXP_ENTITY_DEFINITION_LOADER,
                            useClass: AXMSchedulerJobManagementModuleEntityProvider,
                            multi: true,
                        },
                    ]
                }]
        }] });

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

export { AXMSchedulerJobManagementModule, AXMSchedulerJobManagementModuleEntityProvider, AXMSchedulerJobManagementModuleMenuProvider, AXMSchedulerJobManagementSchedulerJobEntityModule, AXMSchedulerJobManagementSchedulerJobEntityService, AXMSchedulerJobManagementSchedulerJobEntityServiceImpl, RootConfig, schedulerJobFactory };
//# sourceMappingURL=acorex-modules-scheduler-job-management.mjs.map
